Click to See Complete Forum and Search --> : Simulate Keypress
sail3005
Jan 31st, 2001, 06:57 PM
How can i simulate a key press, in the console window? Preferably not using MFC or API, if possible, but if not thats ok.
Thanks
Chris
Feb 1st, 2001, 12:03 PM
Use the keybd_event API function will do.
Vlatko
Feb 1st, 2001, 01:54 PM
In case you don't have the documantetion:
keybd_event
The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
Windows NT: This function has been superseded. Use SendInput instead.
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
Parameters
bVk
Specifies a virtual-key code. The code must be a value in the range 1 to 254.
bScan
Specifies a hardware scan code for the key.
dwFlags
A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags. Value Meaning
KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo
Specifies an additional 32-bit value associated with the key stroke.
Return Values
This function has no return value.
Remarks
Although keybd_event passes an OEM-dependent hardware scan code to the system, applications should not use the scan code. The system converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications.
An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window.
You can also use PostMessage to send the WM_CHAR message.
sail3005
Feb 1st, 2001, 05:56 PM
vlatko, is that documentation from the MSDN library? If it is, do you know where i can get the latest version? Maybe i could anwser some of my own questions then. If it isin't from MSDN, could you tell me where to get it?
Chris
Feb 1st, 2001, 07:21 PM
I think it from MSDN too. Juz in case you need the lastest MSDN reference you can always goto the MSDN Online Library (http://msdn.microsoft.com/library/default.asp)
sail3005
Feb 1st, 2001, 10:11 PM
well is that the full MSDN library? i thought that you had to subscribe to it or something?
sail3005
Feb 1st, 2001, 10:12 PM
oh, stupid me, maybe i should read the site before i ask a question..
haha
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.