Press any key to see everything a JavaScript KeyboardEvent reports: event.key, event.code, the legacy keyCode and which, the key location and modifier state. Copy any value or a ready-made keydown handler, and look up common codes in the table below.
⌨
Press any key to get its JavaScript keycode
Click here first if nothing happens. On a phone, tap the box below to open the keyboard.
13
Enter
ShiftCtrlAltMeta ⌘/⊞Caps Lock
Code snippet
Event log
Event
key
code
keyCode
Mods
Key presses appear here.
Key code reference
Key
event.key
event.code
keyCode
Click a row to copy its event.code. Firefox differs for ; (59), = (61) and - (173).
Advertisement
Advertisement
How to use the JavaScript Keycode Finder
Press any key on your keyboard. The big number is the keyCode and the cards show every property of the event.
Try combinations such as Shift+A or Ctrl+S: the modifier pills light up and event.key shows the resulting character.
Click a card to copy its value, for example the event.code string.
Copy the code snippet: choose whether to match by event.key or event.code and paste the handler into your project.
Look up a key without pressing it by searching the reference table.
key, code, keyCode and which compared
Property
What it tells you
Example (Shift + 2 on a US keyboard)
Status
event.key
The character or key name produced, after layout and modifiers
"@"
Recommended
event.code
The physical key, independent of layout
"Digit2"
Recommended
event.keyCode
A numeric code, mostly based on the unshifted key
50
Deprecated
event.which
Same as keyCode for keydown and keyup
50
Deprecated
event.location
0 standard, 1 left, 2 right, 3 numpad
0
Current
Choosing key or code
Use event.key when the meaning matters: keyboard shortcuts such as Ctrl+S, closing a dialog with Escape, submitting with Enter, or reading typed characters. It respects the user's keyboard layout, so a French user pressing the key labelled "Z" gets "z".
Use event.code when the position matters: WASD movement in a game, piano or drum keys, or any layout where the physical arrangement is the point. On an AZERTY keyboard the WASD keys are labelled ZQSD but still report KeyW, KeyA, KeyS and KeyD.
Avoid keyCode and which in new code. They remain for old browsers and existing scripts, but values differ between browsers for some punctuation keys and are ambiguous for non-US layouts.
Common pitfalls
The space bar's event.key is a single space character " ", not "Space". Its event.code is "Space".
With Shift held, letter keys report an upper-case event.key ("A"), so compare with event.key.toLowerCase() for case-insensitive shortcuts.
On macOS use event.metaKey (⌘) where Windows and Linux use event.ctrlKey for shortcuts like save and copy.
The keypress event is deprecated. Use keydown for keys and the input event for text changes.
Check event.isComposing (or keyCode 229) to ignore key events while an input method is composing Chinese, Japanese or Korean text.
Frequently asked questions
What is the difference between event.key and event.code?
event.key is the value the key produces, taking layout and modifiers into account: "a", "A", "Enter" or "é". event.code is the physical key position, independent of layout: the key next to Tab is always "KeyQ", even on an AZERTY keyboard where it types "a". Use key for text and shortcuts by character, code for game controls such as WASD.
Is keyCode deprecated?
Yes. keyCode and which are deprecated in the UI Events specification and their values vary between browsers and keyboard layouts. They still work in all browsers for compatibility, but new code should use event.key or event.code.
What is the keyCode for Enter, Escape and Space?
Enter is 13, Escape is 27, Space is 32, Tab is 9 and Backspace is 8. The arrow keys are 37 (left), 38 (up), 39 (right) and 40 (down). With modern code, compare event.key to "Enter", "Escape", " " (a space), "Tab" or "ArrowLeft".
Why do some keys show different keyCodes in Firefox?
A few punctuation keys differ: in Firefox semicolon is 59, equals is 61 and minus is 173, while Chrome, Edge and Safari use 186, 187 and 189. The Meta (Windows / Command) key is 91 in Chromium browsers and 224 in older Firefox versions. event.code avoids these differences.
What does event.location mean?
It tells you which copy of a key was pressed: 0 for a standard key, 1 for the left one (left Shift, Ctrl, Alt or Meta), 2 for the right one and 3 for the numeric keypad.
Why does my phone show keyCode 229 or "Unidentified"?
Many virtual keyboards on Android use an input method (IME) that reports keydown with keyCode 229 and key "Unidentified" while composing text. Listen to the input or beforeinput event to read the typed text on mobile.
Why can't I detect some keys like Fn or Print Screen?
The Fn key is handled inside the keyboard and never reaches the browser. Some keys and shortcuts are reserved by the operating system or browser, such as Print Screen on some systems, Ctrl+W or Alt+Tab, so a web page cannot receive or block them.