Home > Web Front-end > JS Tutorial > Differences and connections between javascript KeyDown, KeyPress and KeyUp events_javascript skills

Differences and connections between javascript KeyDown, KeyPress and KeyUp events_javascript skills

WBOY
Release: 2016-05-16 18:40:37
Original
1138 people have browsed it

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

1. KeyPress is mainly used to receive letters, numbers and other ANSI characters
KeyDown and KeyUP event processes can usually capture all keyboard keys except PrScrn (special keys of special keyboards are not discussed here

2. KeyPress can only capture single characters
KeyDown and KeyUp can capture key combinations.

3. KeyPress does not display the physical state of the keyboard (SHIFT key), but only passes each character. The uppercase and lowercase forms are interpreted as different key codes

, that is, as two different characters. KeyDown and KeyUp use two parameters to interpret each key value letter. uppercase and lowercase versions of characters: keycode — indicates the physical key (returns A and a as the same key) and shift — indicates the state of the shift key and returns either A or a .

5. KeyPress does not distinguish between the numeric characters of the small keyboard and the main keyboard.
KeyDown and KeyUp distinguish the numeric characters of the small keyboard and the main keyboard. 6. KeyDown and KeyUp events are. Occurs when a key is pressed (KeyDown) or released (KeyUp)
Since the keys on the keyboard are generally released immediately (this is different from the mouse), there is not much difference between the two events. .

Moreover, there is another difference between up and the other two: up must be used to determine the modified status of the key.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template