keybd_event Function
Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Platforms
- Windows 95: Supported.
- Windows 98: Supported but Obsolete; use SendInput instead.
- Windows NT: Requires Windows NT 3.1 or later but Obsolete with Windows NT 4.0 with Service Pack 3 (SP3) or later; use SendInput instead.
- Windows 2000: Supported but Obsolete; use SendInput instead.
- Windows CE: Requires Windows CE 1.0 or later but Obsolete with Windows CE 2.0 or later; use SendInput instead.
Description & Usage
keybd_event simulates keyboard input by placing a keyboard input event into the input stream. The function can simulate a single press or release of a single key. This function should only be used when a key's state changes. For example, do not tell the function to simulate pressing the Z key if the Z key is already pressed.
Return Value
keybd_event does not return a value.
Visual Basic-Specific Issues
None.
Parameters
- bVk
- The virtual-key code of the key to simulate pressing or releasing.
- bScan
- Reserved -- set to 0.
- dwFlags
- A combination of the following flags specifying what kind of keyboard input to synthesize:
- KEYEVENTF_EXTENDEDKEY
- Prefix the scan code with a prefix byte having the value &HE0.
- KEYEVENTF_KEYUP
- The key specified in bVk is being released. If this flag is not specified, the key is being pressed.
- dwExtraInfo
- An additional 32-bit value associated with the keyboard event.
Constant Definitions
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Example
' Simulate the user pressing Alt+Space followed by N. This
' key combination will minimize the active window.
' Hold the Alt key while typing Space.
keybd_event VK_MENU, 0, 0, 0 ' press Alt
keybd_event VK_SPACE, 0, 0, 0 ' press Space
keybd_event VK_SPACE, 0, KEYEVENTF_KEYUP, 0 ' release Space
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0 ' release Alt
' Type the N key.
keybd_event VK_N, 0, 0, 0 ' press N
keybd_event VK_N, 0, KEYEVENTF_KEYUP, 0 ' release N
Related Functions
mouse_event, SendInput
Category
Keyboard
Back to the index.
Last Modified: August 7, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information
Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/k/keybd_event.html