HTML DOM KeyboardEvent

KeyboardEvent Object

An event occurs when the user presses a key on the keyboard, which belongs to the KeyboardEvent object.

Attribute/Method Description
altKey Returns whether the "ALT" key was pressed when the key event was triggered.
charCode Returns the Unicode character code of the key that triggered the onkeypress event.
code Returns the code of the key that triggered the event.
ctrlKey Returns whether the "CTRL" key was pressed when the key mouse event occurred.
getModifierState() Returns true if the specified key is activated.
isComposing Returns whether the state is being composed by the event.
key Returns the key value represented by the event.
keyCode Returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.
location Returns the position of the key on the keyboard or device.
metaKey Returns whether the "META" key was pressed when the key event was triggered.
repeat Returns whether a key is held down repeatedly.
shiftKey Returns whether the "SHIFT" key was pressed when the key event was triggered.
which Returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.

Inherited Properties and Methods

KeyboardEvent inherits all properties and methods from the following objects:

UiEvent

Event Object

Event Type

These event types belong to the KeyboardEvent object:

Event Description
onkeydown This event occurs when the user is pressing a key.
onkeypress This event occurs when the user presses a key.
onkeyup This event occurs when the user releases a key.