These events that are triggered when a key is pressed are in the following order:
- keydown Event: This event occurs when the user has pressed down the key. It will occur even if the key pressed does not produce a character value.
- keypress Event: This event occurs when the user presses a key that produces a character value. These include keys such as the alphabetic, numeric, and punctuation keys. Modifier keys such as ‘Shift’, ‘CapsLock’, ‘Ctrl’ etc. do not produce a character, therefore they have no ‘keypress’ event attached to them.
- keyup Event: This event occurs when the user has released the key. It will occur even if the key released does not produce a character value.
Note that different browsers may have different implementations of the above events. The onKeyDown, onKeyPress, and onKeyUp events can be used to detect these events respectively.
The below example shows different events that get triggered when a key is pressed in their respective order.
- HTML | onkeyup Event Attribute
- HTML | DOM onkeyup Event
- HTML | onkeypress Attribute
- HTML | DOM onkeypress Event
- Ways to capture the backspace and delete on the onkeydown event
- HTML | onkeydown Event Attribute
- HTML | DOM onkeydown Event
- How to bind 'touchstart' and 'click' events but not respond to both ?
- Difference between DOMContentLoaded and load Events
- CSS | pointer-events Property
- Node.js Events
- ES6 | Events
- AngularJS | Events
- Keyboard Events in ElectronJS
- How to handle events in dynamically created elements in jQuery ?
- How to disable mouseout events triggered by child elements?
- jQuery Mouse Events
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.