KeyDown the difference between keyPress keyUp events

Source: Internet
Author: User

KeyDown the difference between keyPress keyUp events

A sequence of triggers

Obviously, the order in which the events occur is:KeyDown --KeyPress-KeyUpWhen you hold down a key for some time and then release it, the result is: KeyDown
KeyPress
KeyDown
KeyPress
KeyDown
KeyPress
KeyDown
KeyPress ...
KeyUpn KeyDown and N keypress,1 keyup, System set time interval.two specific differences

KeyPress is mainly used to receive ANSI characters such as letters, numbers, etc.
The KeyDown and KeyUP event processes can handle any
Keystrokes that are not recognized by KeyPress, such as: function keys (
F1-F12), edit keys, anchor keys, and any of these keys
and keyboard shift key combinations and so on. With KeyDown and
KeyUp events are different, KeyPress does not show
The physical state of the keyboard (the SHIFT key), but only the
Hand one character. KeyPress will each character of the large,
Lowercase forms are interpreted as different key codes, i.e., as two
Different characters. and KeyDown and KeyUp use two kinds of
Parameters explain the uppercase and lowercase forms of each character:
keycode-Displays physical keys (A and a are used as
Same key return) and shift-indicator SHIFT + key
The state of the key and returns one of a or a.
KeyDown, KeyUp event is when pressed (KeyDown)
or loosen (KeyUp) a key when it occurs.
Because the keyboard key is usually pressed, it will be released immediately.
(This is not the same as the mouse), so the two events use little difference.

KeyDown, from the performance point of view is to press any key,
Press the character, if the text box is not yet
The event that occurs before the text box is displayed.

KeyUp occurs when the button is released,
The character is now entered into the text box

KeyPress the entire key action is complete, only the sound
No response to these control keys, such as Ctrl,alt and so on.


Although literally understood, KeyDown is the meaning of pressing a key,
But in fact the fundamental difference is that the system is KeyDown
Return the code for the keyboard, and then by the TranslateMessage function
Translated into characters, the character value is returned by KeyPress.
So the code returned in KeyDown is the keyboard,
Instead, KeyPress returns an ASCII character. So depending on your
The purpose, if only to read characters, with KeyPress,
If you want to read the status of each key, use KeyDown.
Say KeyDown is pressed, KeyPress is pressed and loosened,
Is wrong. What if you keep pressing the key? At this time, constantly
Produce KeyDown and KeyPress.

KeyDown, KeyUp Events
These events are pressed when an object has focus (KeyDown)
or loosen (KeyUp) a key when it occurs.
(to interpret ANSI characters, you should use the KeyPress event.) )
KeyPress Events
This event occurs when the user presses and releases an ANSI key.
The object that has the focus receives the event. A form is only in its
There are no visible and valid controls or the KeyPreview property is set to
True to receive the event. A KeyPress event can be
Reference any printable keyboard character, one from the standard letter
The characters of the table or one of the few special characters with CTRL
The key combination, and the Enter or BACKSPACE key.
KeyPress Event process in the Intercept TextBox or
The keystrokes entered by the ComboBox control are very useful.
It can immediately test the validity of a keystroke or the character input
It is processed in a format. Change KeyAscii
The value of the parameter changes the displayed character

KeyDown the difference between keyPress keyUp events

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.