Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to generate Keyboard events ?

How to generate Keyboard events ?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 3831761
    wrote on last edited by
    #1

    Hi, How to generate Keyboard events. I want to generate Alt+Tab Event in middle of my application. How to generate Alt+Tab event in a dialog based application. Thanks in advance. With best wishes.

    E _ A 3 Replies Last reply
    0
    • U User 3831761

      Hi, How to generate Keyboard events. I want to generate Alt+Tab Event in middle of my application. How to generate Alt+Tab event in a dialog based application. Thanks in advance. With best wishes.

      E Offline
      E Offline
      Emilio Garavaglia
      wrote on last edited by
      #2

      Just call SendMessage to the intended window, giving the arguments the value you want to expect from that event.

      2 bugs found. > recompile ... 65534 bugs found. :doh:

      1 Reply Last reply
      0
      • U User 3831761

        Hi, How to generate Keyboard events. I want to generate Alt+Tab Event in middle of my application. How to generate Alt+Tab event in a dialog based application. Thanks in advance. With best wishes.

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        SendInput[^]

        «_Superman_» I love work. It gives me something to do between weekends.

        1 Reply Last reply
        0
        • U User 3831761

          Hi, How to generate Keyboard events. I want to generate Alt+Tab Event in middle of my application. How to generate Alt+Tab event in a dialog based application. Thanks in advance. With best wishes.

          A Offline
          A Offline
          Adam Roderick J
          wrote on last edited by
          #4

          keybd_event http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx[^]

          K U 2 Replies Last reply
          0
          • A Adam Roderick J

            keybd_event http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx[^]

            K Offline
            K Offline
            Kushagra Tiwari
            wrote on last edited by
            #5

            You can use either SendMessage() or PostMessage() depending on you requirement. There are a few subtle differences in the ways you can send messages in Windows, but the basic difference between PostMessage and SendMessage is that SendMessage sends a message to another window immediately by calling that window's procedure and waiting for it to return, whereas PostMessage queues the message in an MSG structure and returns immediately"without waiting. MSG is short for message, not monosodium glutamate. With SendMessage, the receiving app processes the message immediately, rather than at some later time, by fetching it from its queue. For example, suppose you write: pWnd->SendMessage(WM_KEYDOWN); pWnd->PostMessage(WM_KEYDOWN); There are different indicators for which key was pressed .Kindly, go through that list and do the apporopiate :) Kushagra I hate coding but I love to develop :)

            1 Reply Last reply
            0
            • A Adam Roderick J

              keybd_event http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx[^]

              U Offline
              U Offline
              User 3831761
              wrote on last edited by
              #6

              Thank you. Using keybd_event how to generate Alt+Tab. I tried both of the below options but failed. 1 ------------ keybd_event( VK_MENU ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 ); keybd_event( VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 ); keybd_event( VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); keybd_event( VK_MENU ,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); 2 ------------ keybd_event( VK_MENU | VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 ); keybd_event( VK_MENU | VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); Please let me know how to use for Alt+Tab combination to change the window.

              A 1 Reply Last reply
              0
              • U User 3831761

                Thank you. Using keybd_event how to generate Alt+Tab. I tried both of the below options but failed. 1 ------------ keybd_event( VK_MENU ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 ); keybd_event( VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 ); keybd_event( VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); keybd_event( VK_MENU ,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); 2 ------------ keybd_event( VK_MENU | VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0 ); keybd_event( VK_MENU | VK_TAB ,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); Please let me know how to use for Alt+Tab combination to change the window.

                A Offline
                A Offline
                Adam Roderick J
                wrote on last edited by
                #7

                There is small mistake in the code hardware scan code is wrong it should be for alt 0X12 and for tab 0X09 i put delay just to see the output. :) keybd_event( VK_MENU ,0x12,KEYEVENTF_EXTENDEDKEY | 0, 0 ); Sleep(1); keybd_event( VK_TAB ,0x09,KEYEVENTF_EXTENDEDKEY | 0, 0 ); Sleep(1000); keybd_event( VK_TAB ,0x12,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); keybd_event( VK_MENU ,0x09,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0);

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups