Home > Article > Web Front-end > Differences and connections between javascript KeyDown, KeyPress and KeyUp events_javascript skills
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.