Windows program design Reading Notes-keyboard.

Source: Internet
Author: User

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

Related Article

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.