Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
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
' This code is licensed according to the terms and conditions listed here. ' 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
See Also
mouse_event, SendInput
Category
Keyboard
Go back to the alphabetical Function listing. Go back to the Reference section index.
Last Modified: August 7, 1999 This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000 Go back to the Windows API Guide home page. E-mail: vbapi@vbapi.com Send Encrypted E-Mail This page is at http://www.vbapi.com/ref/k/keybd_event.html