The differences between JavaScript KeyDown, KeyPress and KeyUp events and their connection _javascript skills

Source: Internet
Author: User
KeyDown: Occurs when the key is pressed while the control has focus.
KeyPress: Occurs when the key is pressed while the control has focus.
KeyUp: Occurs when a key is released while the control has focus.

1, KeyPress mainly used to receive letters, numbers and other ANSI characters
KeyDown and KeyUP event procedures can usually capture the keyboard except PRSCRN all keys (special keys for special keyboards are not discussed here

2, KeyPress can only capture a single character
KeyDown and KeyUp can capture key combinations.

3, KeyPress does not show the physical state of the keyboard (Shift key), but only passing a character. KeyPress the large and lowercase form of each character as a different key code solution

Interpretation, that is, as two different characters.
KeyDown and KeyUp cannot determine the size of key-value letters. KeyDown and KeyUp explain the uppercase and lowercase forms of each character with two parameters: keycode-

The physical keys (returning A and a as the same key) and shift-indicate the state of the SHIFT + key key and return either a or a.

5, KeyPress does not distinguish between the keypad and the main keyboard numeric characters.
KeyDown and KeyUp distinguish the numeric characters of the keypad and the main keyboard.

6, KeyDown, KeyUp event occurs when a key is pressed (KeyDown) or released (KEYUP).
Because the keyboard usually press the key will be immediately released (this is different from the mouse), so the two events using which difference is not.

Also, the up and the other two have a difference: to determine the state of the key modified must use up.

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.