DOM KeyboardEvent.key Property
The key property of a keyboard event gives the value of the key pressed, such as a, Enter or ArrowUp, taking the keyboard layout and Shift into account.
Description
The read-only key property returns the value of the key pressed. For printable keys it's the character typed, so it reflects the keyboard layout and modifier keys ("a" or "A"). Other keys have names such as "Enter", "Tab", "Escape", "Backspace", "ArrowUp" and " " for the space bar.
Use key for shortcuts that relate to what's printed on the key, and code when the physical position matters, such as WASD controls in games.
When an input method editor (IME) is in use, for example when typing Chinese or Japanese, key may be "Process" and isComposing is true; ignore those events in shortcut handlers. The full list of named key values is defined in the UI Events specification.
Syntax
event.keyValue
A string: the character produced, such as "a" or "A", or a key name such as "Enter", "Escape" or "ArrowLeft".
Example
Browser Support
The following information will show you the current browser support for the KeyboardEvent.key property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





