Wm_char, wm_keydown, and wm_syskeydown messages

Source: Internet
Author: User

Both wm_keydown and wm_char are keyboard messages. The translatemessage function has converted the key message into a character message, so you need to select the event in the wndproc function. For example, if you type the "D" key, you should select wm_char, because wm_char is only a letter and does not contain special characters such as ctrl.
If you type "Ctrl + D" on the keyboard, select wm_keydown because wm_keydown contains both letters and special characters.
Wm_char is generated after the wm_keydown message translate () and then sent to the window. For example, press the "D" key to generate the wm_keydown message. After the message is processed by translate (), it becomes the wm_keydow and wm_char messages passed to the window.

Wm_syskeydown accepts shortcut keys or system command keys, such as the Alt key. Therefore, when the Alt key is captured, it is invalid in wm_keydown, which must be in wm_syskeydown. CTRL and shift do not belong to wm_syskeydown.

The process of keyboard messages starts from the preprocessmessage method and follows the logic sequence described in the table. (Understanding this process may help you understand the above three messages)

 

Method Description Result
Processcmdkey This method checks whether the key is a command key, such as a shortcut key or menu shortcut key. If the method returns true, the key message is not scheduled and no key event occurs.
If the method returns false, IsInputKey is called to check whether the key is a regular input key.
IsInputKey This method checks whether the buttons are regular keys. If the method returns true, it indicates that the key is a regular character and will call ProcessKeyMessage for message processing.
If the method returns false, ProcessDialogKey is called.
ProcessDialogKey This method checks whether the buttons are navigation keys, such as Esc, Tab, enter, or arrow keys.
If the control does not process the key, the ProcessDialogKey of the base control or parent control is called until the top control in the hierarchy.
If this method returns true, message preprocessing is completed and no key event is generated.
If this method returns false, ProcessKeyMessage is called for message processing.
ProcessKeyMessage This method processes all keyboard messages received by the WndProc method of the control If the control has a parent level, the ProcessKeyPreview of the parent level is called.
If the control does not have a parent or the parent ProcessKeyPreview does not process the message, the ProcessKeyEventArgs
ProcessKeyPreview This method sends keyboard messages to the control's parent Control If this method returns true, no key event will occur.
If this method returns false, ProcessKeyEventArgs is called.
ProcessKeyEventArgs This method raises the KeyDown event

 

 

From http://hyhscut.blog.163.com/blog/static/1074632120096100281207/

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.