keybd_event
Windows提供了一个模拟键盘函数Keybd_event(),使用该函数可以相应的屏蔽键盘的动作。Keybd_event()函数能触发一个按键事件。
函数原型
- VOID keybd_event ( BYTE bVk, BYTE bScan, DWORD dwFlags,
ULONG_PTR dwExtraInfo ) ;
从函数原型,进行参数解析
第一个为按键的虚拟键值,如回车键为vk_return, win键为VK_LWIN,其他的值参见如下;
The following table shows the symbolic constant names, hexadecimal values, and keyboard equivalents for the virtual key codes used by the Windows Embedded Compact operating system. The codes are listed in numeric order. To create a hot key, you can combine any of the codes with a modifier key.
Virtual key codes
Symbolic constant Hexadecimal value Mouse or keyboard equivalent
VK_LBUTTON 0x01 Left mouse button.
VK_RBUTTON 0x02 Right mouse button.
VK_CANCEL 0x03 Control-break processing.
VK_MBUTTON 0x04 Middle mouse button on a three-button mouse.
0x05-0x07 Undefined.
VK_BACK 0x08 BACKSPACE key.
VK_TAB 0x09 TAB key.
0x0A-0x0B Undefined.
VK_CLEAR 0x0C CLEAR key.
VK_RETURN 0x0D ENTER key.
0x0E-0x0F Undefined.
VK_SHIFT 0x10 SHIFT key.
VK_CONTROL 0x11 CTRL key.
VK_MENU 0x12 ALT key.
VK_PAUSE 0x13 PAUSE key.
VK_CAPITAL 0x14 CAPS LOCK key.
0x15-0x19 Reserved for Kanji systems.
0x1A Undefined.
VK_ESCAPE 0x1B ESC key.
0x1C-0x1F Reserved for Kanji systems.
VK_SPACE 0x20 SPACEBAR.
VK_PRIOR 0x21 PAGE UP key.
VK_NEXT 0x22 PAGE DOWN key.
VK_END 0x23 END key.
VK_HOME 0x24 HOME key.
VK_LEFT 0x25 LEFT ARROW key.
VK_UP 0x26 UP ARROW key.
VK_RIGHT 0x27 RIGHT ARROW key.
VK_DOWN 0x28 DOWN ARROW key.
VK_SELECT 0x29 SELECT key.
0x2A Specific to OEM.
VK_EXECUTE 0x2B EXECUTE key.
VK_SNAPSHOT 0x2C PRINT SCREEN key.
VK_INSERT 0x2D INS key.
VK_DELETE 0x2E DEL key.
VK_HELP 0x2F HELP key.
0x3A-0x40 Undefined.
VK_LWIN 0x5B Left Windows key on a Microsoft Natural Keyboard.
VK_RWIN 0x5C Right Windows key on a Microsoft Natural Keyboard.
VK_APPS 0x5D Applications key on a Microsoft Natural Keyboard.
0x5E-0x5F Undefined.
VK_NUMPAD0 0x60 Numeric keypad 0 key.
VK_NUMPAD1 0x61 Numeric keypad 1 key.
VK_NUMPAD2 0x62 Numeric keypad 2 key.
VK_NUMPAD3 0x63 Numeric keypad 3 key.
VK_NUMPAD4 0x64 Numeric keypad 4 key.
VK_NUMPAD5 0x65 Numeric keypad 5 key.
VK_NUMPAD6 0x66 Numeric keypad 6 key.
VK_NUMPAD7 0x67 Numeric keypad 7 key.
VK_NUMPAD8 0x68 Numeric keypad 8 key.
VK_NUMPAD9 0x69 Numeric keypad 9 key.
VK_MULTIPLY 0x6A Multiply key.
VK_ADD 0x6B Add key.
VK_SEPARATOR 0x6C Separator key.
VK_SUBTRACT 0x6D Subtract key.
VK_DECIMAL 0x6E Decimal key.
VK_DIVIDE 0x6F Divide key.
VK_F1 0x70 F1 key.
VK_F2 0x71 F2 key.
VK_F3 0x72 F3 key.
VK_F4 0x73 F4 key.
VK_F5 0x74 F5 key.
VK_F6 0x75 F6 key.
VK_F7 0x76 F7 key.
VK_F8 0x77 F8 key.
VK_F9 0x78 F9 key.
VK_F10 0x79 F10 key.
VK_F11 0x7A F11 key.
VK_F12 0x7B F12 key.
VK_F13 0x7C F13 key.
VK_F14 0x7D F14 key.
VK_F15 0x7E F15 key.
VK_F16 0x7F F16 key.
VK_F17 0x80 F17 key.
VK_F18 0x81 F18 key.
VK_F19 0x82 F19 key.
VK_F20 0x83 F20 key.
VK_F21 0x84 F21 key.
VK_F22 0x85 F22 key.
VK_F23 0x86 F23 key.
VK_F24 0x87 F24 key.
0x88-0x8F Unassigned.
VK_NUMLOCK 0x90 NUM LOCK key.
VK_SCROLL 0x91 SCROLL LOCK key.
VK_LSHIFT 0xA0 Left SHIFT.
VK_RSHIFT 0xA1 Right SHIFT.
VK_LCONTROL 0xA2 Left CTRL.
VK_RCONTROL 0xA3 Right CTRL.
VK_LMENU 0xA4 Left ALT.
VK_RMENU 0xA5 Right ALT.
0xBA-0xC0 Specific to OEM; reserved. See following tables.
0xC1-0xDA Unassigned.
0xDB-0xDE Specific to OEM; reserved. See following tables.
VK_OFF 0xDF Used to power the device on and off. No keyboard equivalent.
0xE1-0xE4 Specific to OEM.
0xE5 Unassigned.
0xE6 Specific to OEM.
VK_PACKET 0xE7 Used to pass Unicode characters as if they were keystrokes. If VK_PACKET is used with SendInput, then the Unicode character to be delivered should be placed into the lower 16 bits of the scan code. If a keyboard message is removed from the message queue and the virtual key is VK_PACKET, then the Unicode character will be the upper 16 bits of the lparam.
0xE8 Unassigned.
0xE9-0xF5 Specific to OEM.
VK_ATTN 0xF6 ATTN key.
VK_CRSEL 0xF7 CRSEL key.
VK_EXSEL 0xF8 EXSEL key.
VK_EREOF 0xF9 Erase EOF key.
VK_PLAY 0xFA PLAY key.
VK_ZOOM 0xFB ZOOM key.
VK_NONAME 0xFC Reserved.
VK_PA1 0xFD PA1 key.
VK_OEM_CLEAR 0xFE CLEAR key.
OEMs should make special note of the VK key ranges reserved for specific OEM use: 2A, DB-E4, E6, and E9-F5.
In addition to the virtual key assignments in the previous table, Microsoft has assigned the following specific OEM virtual keys.
Symbolic constant Hexadecimal value Mouse or keyboard equivalent
VK_OEM_SCROLL 0x91 None.
VK_OEM_1 0xBA ";:" for US.
VK_OEM_PLUS 0xBB "+" any country/region.
VK_OEM_COMMA 0xBC "," any country/region.
VK_OEM_MINUS 0xBD "-" any country/region.
VK_OEM_PERIOD 0xBE "." any country/region.
VK_OEM_2 0xBF "/?" for US.
VK_OEM_3 0xC0 "`~" for US.
VK_OEM_4 0xDB "[{" for US.
VK_OEM_5 0xDC "\|" for US.
VK_OEM_6 0xDD "]}" for US
VK_OEM_7 0xDE "'"" for US.
VK_OEM_8 0xDF None. By default, this is equivalent to VK_OFF.
VK_OEM_AX 0xE1 AX key on Japanese AX keyboard.
VK_OEM_102 0xE2 "<>" or "\|" on RT 102-key keyboard.
For East Asian Input Method Editors (IMEs), the following additional virtual keyboard definitions must be observed.
Symbolic constant Hexadecimal value Description
VK_DBE_ALPHANUMERIC 0x0f0 Changes the mode to alphanumeric.
VK_DBE_KATAKANA 0x0f1 Changes the mode to Katakana.
VK_DBE_HIRAGANA 0x0f2 Changes the mode to Hiragana.
VK_DBE_SBCSCHAR 0x0f3 Changes the mode to single-byte characters.
VK_DBE_DBCSCHAR 0x0f4 Changes the mode to double-byte characters.
VK_DBE_ROMAN 0x0f5 Changes the mode to Roman characters.
VK_DBE_NOROMAN 0x0f6 Changes the mode to non-Roman characters.
VK_DBE_ENTERWORDREGISTERMODE 0x0f7 Activates the word registration dialog box.
VK_DBE_ENTERIMECONFIGMODE 0x0f8 Activates a dialog box for setting up an IME environment.
VK_DBE_FLUSHSTRING 0x0f9 Deletes the undetermined string without determining it.
VK_DBE_CODEINPUT 0x0fa Changes the mode to code input.
VK_DBE_NOCODEINPUT 0x0fb Changes the mode to no-code input.
OEMs should not use the unassigned portions of the virtual key (VK) mapping tables. If manufacturers require additional VK mappings, they should reuse some of the current manufacturer-specific and vendor-specific assignments.
第二个参数为扫描码,一般不用设置,用0代替就行;
第三个参数为选项标志,如果为keydown(按键按下)则置0即可,如果为keyup(按键抬起)则设成"KEYEVENTF_KEYUP"或者2;
第四个参数一般也是置0即可。