CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    13

    Keyboard simulation

    I want to simulate in the UI this situation: the user press at the same time the folowing keys:
    <Ctrl>, <Alt> and <A>
    If I need only the simulation for one key I do this:
    pWnd->PostMessage ( WM_KEYDOWN, 'Y', 0 );
    or
    pWnd->PostMessage ( WM_KEYDOWN, VK_RETURN, 0 );
    but how can I do this (if it is possible) for more than a key ???

    I don't care what kind of solution somebody has, but I need one.

    Thanks a lot.

    Emanuil Achim
    [email protected]



  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Keyboard simulation

    Why not make an accelerator entry in the resources that maps a command ID to <Ctrl> <Alt> <A>? Then it's as simple as a WM_COMMAND message when the user presses this combination.

    If this is not possible, the only way that I can think of is to call GetKeyboardState(), change the state of the Ctrl and Alt and A virtual keys, and then call SetKeyboardState().

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Re: Keyboard simulation

    Another solution is to post that key combination directly into the keyboard buffer via the keybd_event() win32 function, or for Windows NT you can use SendInput(). Those allow you to map a virtual key code (multiple layers, etc).

    Here's an example of posting the CTRL + ALT + A keys to the keyboard input buffer:
    VOID keybd_event( 65, 6, KEYEVENTF_EXTENDEDKEY, GetMessageExtraInfo() );



    The "65" is the "A" value.
    The "6" is the CTRL (2) OR'd with the ALT (4) value to come up with 6.

    Hope that helps..

    - Troy

  4. #4
    Join Date
    May 1999
    Posts
    13

    Re: Keyboard simulation

    I tried this function:
    keybd_event( 'A', VK_SHIFT, KEYEVENTF_EXTENDEDKEY, GetMessageExtraInfo() );
    But if the focus is in a edit field it types the
    "a" and NOT "A"

    By the way I have NT 4 and VC++ 5.0. I am looking for the function SendInput() but I don't found it. The VC help says that it's in the <winuser.h> but there is not. Maybe I must install something special ?!


  5. #5
    Join Date
    Apr 1999
    Location
    Huntsville, Al
    Posts
    27

    Re: Keyboard simulation

    try SetKeyboardState.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured