"Turn" keypress keydown keyup Difference

Source: Internet
Author: User

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.
This post is from Zdnetchina Chinese community
http://bbs.zdnet.com.cn/, paste address: http://bbs.zdnet.com.cn/viewthread.php?tid=778043


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.

When you press a key (not yet released), it triggers the KeyDown
The KeyPress event is triggered when you release it.

That is to say KeyDown just press a key will trigger, and KeyPress
It will not trigger until it is pressed and released.

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

From:http://www.cnblogs.com/zhchongyao/archive/2010/01/26/1656701.html

"Turn" keypress keydown keyup Difference

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.