In JS three events are key events, let's take a look at the keydown,keyup,keypress these three events in the difference where it is, I hope the example can help you.
1. Keys to raise events
Non-character keys do not raise KeyPress events, but non-word keys can raise KeyDown and KeyUp events. The KeyPress event Keychar property can get the characters entered.
2. Time caused by the event
The KeyDown and KeyPress events occur when the key is pressed, and the KeyUp event occurs when the key is released.
3. Sequence of occurrences
KeyDown-> KeyPress-> KeyUp. If you press a key for a long time to loosen up, the event that occurs is: KeyDown-> KeyPress-> KeyDown-> KeyPress-> KeyDown,-> KeyPress-> ...-> KeyUp.
Attention:
KeyDown triggered, not necessarily trigger KeyUp, when KeyDown pressed, drag the mouse, then will not trigger the KeyUp event.
KeyPress is used primarily to capture numbers (note: Symbols that include shift+ numbers), letters (note: include case), keypad, and so on except f1-12, SHIFT, Alt, Ctrl, Insert, Home, PgUp, Delete, end, PgDn, ANSI characters ScrollLock, Pause, NumLock, {Menu key}, {Start key}, and directional keys
KeyDown and KeyUp can usually capture the keyboard except PRSCRN all keys (special keys for special keyboards are not discussed here)
KeyPress can only capture a single character
KeyDown and KeyUp can capture key combinations.
KeyPress can capture the case of a single character
KeyDown and KeyUp for a single character capture keyvalue are a value, that is, can not determine the case of a single character.
KeyPress does not distinguish between numeric characters of the keypad and the main keyboard.
KeyDown and KeyUp distinguish the numeric characters of the keypad and the main keyboard.
None of the Prscrn buttons KeyPress, KeyDown, and KeyUp can be captured.