Keyboard Scan code virtual code concept common Windows keyboard button virtual code

Source: Internet
Author: User

'When a user presses a key,
'1. The keyboard detects this action and sends the scan code to the computer through the keyboard controller;
'Keyboard scan codes are related to specific hardware. Different vendors may have different scanning codes for the same key.
'2. After receiving the scan code, the computer sends it to the keyboard driver;
'3. The keyboard driver converts the scan code to a keyboard virtual code;
'The virtual code has nothing to do with the specific hardware. The virtual code of the same key is always the same for the keyboards of different manufacturers.
'3. Then, the keyboard driver transmits the scan code, virtual code, and other information for the keyboard operation to the operating system;
4. The operating system encapsulates the obtained information in a Keyboard Message and inserts the keyboard message into the message queue.
'5. in the Windows message system, the keyboard message is sent to a window;
'6. After receiving a message, the application in the window can understand the information about keyboard operations and then decide to make a response.

'Keyboard message: wm_keydown
'Repeated rtkey = (INT) wparam; // virtual code
'Lkeydata = lparam; // information about keyboard operations

'The second lparam parameter of the Keyboard Message wm_keydown is complex.
'The function is to specify the number of repetitions, scan code, extended key tag, context code, forward key status tag, and switch status tag.
'Lparam: 4 bytes in length, 32 bits
'0-15 bits: used to specify the number of repetitions of the current message. When you press a key for a period of time,
'The value is the number of times that a key is automatically pressed. If the key takes a long time, multiple messages are sent,
'And the number of repetitions does not accumulate
'16-23: Scan code
'24: Specifies whether the key is an extension key (such as ALT and CTRL). If the value is 1, it indicates an extension key; otherwise, its value is 0.
'25-28: retained
'29: Specifies the context code. For wm_keydown and wm_keyup messages, the total value is 0,
'For the wm_char message, if the Alt key is pressed at the same time, the value is 1; otherwise, the value is 0.
'30: Specifies the pre-key status. If the key is pressed before the message is sent, the value is 1; otherwise, the value is 0.
'31: Specifies the conversion status. For wm_keydown, the total value is 0;

'For wm_char, if the key is released, its value is 1; otherwise, it is 0.

Common windows keyboard key virtual code

Common ASCII codes for keyboards
ESC key vk_escape (27)
Enter the key: vk_return (13)
Tab key: vk_tab (9)
Caps Lock key: vk_capital (20)
Shift key: vk_shift ()
CTRL: vk_control (17)
Alt key: vk_menu (18)
Space key: vk_space (/32)
Backspace key: vk_back (8)
Left logo key: vk_lwin (91)
Right logo key: vk_lwin (92)
Right-click the shortcut key: vk_apps (93)
Insert key: vk_insert (45)
Home Key: vk_home (36)
Page up: vk_prior (33)
Pagedown: vk_next (34)
End key: vk_end (35)
Delete key: vk_delete (46)
Direction key (Direction): vk_left (37)
Direction key (Direction): vk_up (38)
Direction key (→): vk_right (39)
Direction key (Direction): vk_down (40)
F1 key: vk_f1 (112)
F2 key: vk_f2 (113)
F3 key: vk_f3 (114)
F4 key: vk_f4 (115)
F5 key: vk_f5 (116)
F6 key: vk_f6 (117)
F7 key: vk_f7 (118)
F8: vk_f8 (119)
F9 key: vk_f9 (120)
F10 key: vk_f10 (121)
F11 key: vk_f11 (122)
F12 key: vk_f12 (123)
Num Lock key: vk_numlock (144)
Keypad 0: vk_numpad0 (96)
Keypad 1: vk_numpad0 (97)
Keypad 2: vk_numpad0 (98)
Keypad 3: vk_numpad0 (99)
Keypad 4: vk_numpad0 (100)
Keypad 5: vk_numpad0 (101)
Keypad 6: vk_numpad0 (102)
Keypad 7: vk_numpad0 (103)
Keypad 8: vk_numpad0 (104)
Keypad 9: vk_numpad0 (105)
Keypad.: vk_decimal (110)
Keypad *: vk_multiply (106)
Keypad +: vk_multiply (107)
Keypad-: vk_subtract (109)
Keypad/: vk_divide (111)
Pause Break Key: vk_pause (19)
Scroll Lock key: vk_scroll (145)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.