I. keyboard event handling process.
1. Press the key.
2. The windows and keyboard drivers convert hardware scans into formatted messages and place them in the system message queue maintained by windows.
3. Windows receives a message from the system message queue and sends it to the application message queue of the current window with the focus.
4. After the application processes the message, Windows can get the next message from "system message queue.
Because the previous message processing may affect the processing of the next message, for example, the tab button may affect the control that obtains the focus.
II. Key-generated messages:
System key wm_syskeydown wm_syskeyup
Non-system key wm_keydown wm_keyup
The system key is composed of ALT + other keys. Generally, the program ignores the system key and submits it directly to defwindowproc for processing, and then accepts the processed result.
3. keyboard messages
MSG. wparam stores the virtual key code.
MSG. lparam stores other information.
4. Virtual key code.
For the keyboard hardware, the keys are physically encoded according to the key sequence, but not in the program, so there is a set of corresponding virtual key codes.
You can view the definition in the program.
CTRL + pause break = ESC
V. lparam information:
31 bits: switch status --- being pressed or released
30 bits: the previous state of the key
29-bit: Environment Code -- whether to press ALT
24-bit: Extended key flag
23-16 bits: OEM scan?
15-0 bits: Repeated count-Number of unprocessed key messages
Algorithm for retrieving a certain digit: 0x80000000 & msg. lparam
6. check whether a button is pressed:
Getkeystate (ck_shift ). If the result is set to a high position, that is, negative, it indicates the following:
If (getkeystate (vk_shift) <0)
If (hiword (getkeystate (vk_shift )))
7. Key messages and character messages.
Wm_keydown generates wm_char
8. Insert operator Function
Createcaret
Setcaretpos
Getcaretpos
Showcaret
Hidecaret
Destroycaret
Getcaretblinktime
Setcaretblinktime