Click to See Complete Forum and Search --> : Keyboard simulation
Emanuil Achim
May 3rd, 1999, 10:48 AM
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
emanuil_achim@mro.man.de
Paul McKenzie
May 3rd, 1999, 04:00 PM
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
Troy T
May 3rd, 1999, 04:45 PM
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
Emanuil Achim
May 4th, 1999, 02:55 AM
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 ?!
G Kirkham
May 4th, 1999, 09:27 AM
try SetKeyboardState.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.