Keyboard events occur when the user presses or releases a keyboard key.
The onkeydown and onkeyup events fire when a key changes state as it is pressed or released, respectively. These events fire for all keys on the keyboard, including shift state keys such as SHIFT, CTRL, and ALT.
The onkeypress event fires when the user’s keyboard input is translated to a character. These occur, for example, when the user presses letter or number keys, or a combination of shift keys and letters and numbers.
When a keyboard event occurs, the keyCode property of the event object contains the Unicode keycode of the corresponding key. The altKey, ctrlKey, and shiftKey properties specify the state of the ALT, CTRL, and SHIFT keys.
We can change which key is associated with the event by either changing the value of the keyCode property or returning an integer value. We can cancel the event by returning zero or false.
The onhelp event is a special keyboard event that occurs when the user presses the help key ( F1 ).