JavaScript Key Code Viewer
Press a key to see event.key, event.code, keyCode, location and modifiers.
About JavaScript Key Code Viewer
Press any key to see its JavaScript event.key, event.code, keyCode, which, location and modifier state, with a reference table of common key codes.
How to use
- Click the capture area, or move to it with Tab. It says "Listening" while it has focus.
- Press a key or a combination. The large number is
keyCode; the list under it has every value with its own Copy button. - Recent keys keeps the last ten presses. Clear empties both.
- To leave with the keyboard, press Tab to move on or Escape to let go of the area. Both are shown like any other key, and they still work.
What it does
| Value | Meaning |
|---|---|
event.key |
What the key produces with the current layout and modifiers: a, A, Enter, ArrowLeft |
event.code |
The physical key, whatever the layout: KeyA, Digit1, ShiftLeft |
event.keyCode, event.which |
The legacy numbers. Deprecated, and different between browsers for a few keys, but still needed to read old code |
event.location |
0 standard, 1 left, 2 right, 3 number pad. It tells the two Shift keys apart |
| Modifiers | Which of ctrlKey, shiftKey, altKey and metaKey were true |
event.repeat |
true while a key is held down and repeating |
- The values come from the
keydownevent, read only while the capture area has focus. Other keys are stopped from scrolling the page or triggering a browser shortcut while you are in the area. - The Common keys table lists
key,codeandkeyCodefor the keys people look up most, for a US layout, with the values that differ in Firefox.
What it does not do:
- It does not read
keyuporkeypressevents, or mouse buttons. - It needs a physical keyboard. A phone's on-screen keyboard does not open for the capture area.
- It cannot see shortcuts the operating system or browser keeps for itself, such as Alt+Tab or Ctrl+W.
Example
Press Shift + A
event.key A
event.code KeyA
event.keyCode (deprecated) 65
event.which (deprecated) 65
event.location 0 (Standard)
Modifiers shiftKey
event.repeat false
Privacy
Key presses are read only while the capture area has focus. They are shown on the page and kept in memory until you clear them or leave; nothing is sent anywhere or stored.
Frequently asked questions
- What is the difference between event.key and event.code?
- event.key is the meaning of the key and depends on the layout and modifiers; event.code is the physical position. On a French AZERTY keyboard the key labelled A gives key "a" but code "KeyQ". Use key for shortcuts named after a character and code for position-based controls such as WASD.
- Is keyCode deprecated in JavaScript?
- Yes. Both event.keyCode and event.which are deprecated in the UI Events standard, although browsers still support them. New code should use event.key or event.code.
- What is the keyCode for Enter?
- Enter is 13. Other common ones are Backspace 8, Tab 9, Escape 27, Space 32 and the arrow keys 37 to 40 in the order left, up, right, down.
- Why is keyCode 229?
- A keyCode of 229 means an input method editor is processing the key, as happens when typing Chinese, Japanese or Korean and with many on-screen keyboards. The real key is not reported; check event.isComposing and wait for the input event.