I have studied the knowledge of KeyDown, KeyPress, and KeyUp. Let's explain it with the following questions:
1. What is the sequence of the three events?
2. Does KeyUp be triggered after KeyDown is triggered?
3. Definitions of three events
4. Differences between KeyDown, KeyUp, and KeyPress
5. How do I differentiate whether a keypad is used?
6. Can three PrScrn events be captured?
7. Can I capture the {menu key} and {START key} KeyPress?
8. How to capture system Keys?
9. How can I capture the PrScrn button event?
(1) key events occur in the following order:
KeyDown
KeyPress
KeyUp
(2) After KeyDown is triggered, KeyUp may not be triggered. When KeyDown is pressed, drag the mouse to trigger the KeyUp event.
(3) Definition
KeyDown: The Key is pressed when the control has focus.
KeyPress: The Key is pressed when the control has focus. (The difference between the following and KeyDown)
KeyUp: when the control has focus, the key is released.
(4) differences between KeyPress, KeyDown, and KeyPress
1. keyPress is mainly used to capture numbers (Note: including Shift + digit symbols) and letters (Note: including uppercase and lowercase), keypad, in addition to F1-12, SHIFT, Alt, Ctrl, Insert, Home, PgUp, Delete, End, PgDn, ScrollLock, Pause, NumLock, {menu key}, {START key} and ANSI characters outside the direction key
KeyDown and KeyUp can usually capture all the buttons on the keyboard except PrScrn (the special keys on the special keyboard are not discussed here)
2. KeyPress can only capture a single character
KeyDown and KeyUp can capture the combination of keys.
3. KeyPress can capture the case sensitivity of a single character
4. Both KeyDown and KeyUp have a value for the KeyValue captured by a single character, that is, the case of a single character cannot be determined.
5. KeyPress does not distinguish between keypad and keypad numeric characters.
KeyDown and KeyUp distinguish between numbers on the keypad and the primary keypad.
6. The PrScrn keys KeyPress, KeyDown, and KeyUp cannot be captured.
(5) Determination of system key combinations
When using the keyboard, the key combination function similar to CTRL + SHIFT + ALT is usually used. How can we determine this?
The KeyUp event can be used for processing (here we will explain why KeyDown is not required, because CTRL, SHIFT, and ALT are always pressed when determining KeyDown, then, if you add another key, you cannot accurately capture the key combination. Therefore, you cannot accurately determine the key combination by using the KeyDown event)
(6) Capture PrScrn key events
You can use a hook to determine the PrScrn button event. The Hook can obtain any keyboard event.