Keycode Finder
A keycode finder for developers: press any key and see its event.key, event.code, the deprecated keyCode and which, the location value and the modifier state, each with a one-click copy, plus a history of the last ten keys and a JavaScript or React snippet filled in with the key you pressed. Below the tool is a full key code table you can filter, and a plain explanation of why key and code exist, when to use which, and what breaks on non-US layouts and with input method editors.
Click here, then press any key
—
Result class: Measured
event.key- —The character or key name after layout and modifiers (what the user typed).
event.code- —The physical key position, independent of layout and modifiers.
event.keyCode- —Legacy numeric code. Deprecated; kept for old code.
event.which- —Legacy alias of keyCode. Deprecated.
event.location- —0 standard · 1 left · 2 right · 3 numpad.
- Modifiers
- —ctrlKey · shiftKey · altKey · metaKey · repeat
document.addEventListener('keydown', (e) => {
if (e.code === 'KeyA') {
// physical key, any layout
}
if (e.key === 'a') {
// typed "a", layout-dependent
}
});Settings
Runs in your browser. Nothing is uploaded.
How to use
- Click the frame and press a key. The card shows event.key, event.code, keyCode, which and location, with the modifier state; the big label is the code (or the key when the browser gives no code).
- Copy any value with the button next to it, or copy the snippet, which uses the last key you pressed in a keydown handler; switch between JavaScript and React in Settings.
- Use the filter box under the table to find a key by name, code or number; the table is static, so it is searchable by your browser's find as well.
- Turn off "Prevent default actions" in Settings if you want keys like Tab or F5 to behave normally while the frame is focused; by default the page swallows them so you can read their values.
Press a key to get its code
Click inside the frame and press any key; the card fills with the five values a keyboard event carries and the modifier state, and the big label shows the code. Each value has a copy button, the last ten keys collect underneath, and the snippet at the bottom is rewritten with the key you just pressed, in JavaScript or React. Everything comes directly from the browser’s KeyboardEvent, so the result class is Measured, and the values are exactly what your own handler would receive in this browser on this operating system, which is the point: a key code table tells you what a key should report, this page tells you what it does report here. By default the page prevents the browser’s own actions for the keys you press while it has focus, so Tab stays in the frame and F5 does not reload; Settings turns that off. The keyboard tester shows the same codes for every key in its event log if you want to see a whole board at once, and the Mac keyboard tester does the same with Apple’s key names.
event.key vs event.code vs keyCode
Three properties describe one key press, and they answer different questions. event.key answers “what did the user type?”: a character (“a”, “A”, “é”, “ß”) or a named key (“Enter”, “ArrowLeft”, “Shift”), after the operating system’s keyboard layout, dead keys and modifiers have done their work. It is what you want for text, for shortcuts you describe to users (“press S to save”), and for anything where the letter matters. event.code answers “which physical key was that?”: a name for the key’s position, such as KeyQ or Digit1 or ShiftLeft, that MDN describes as a value that “isn’t altered by keyboard layout or the state of the modifier keys”. It is what you want for games and anything that treats the keyboard as a set of buttons: WASD stays in the same place under the left hand on an AZERTY board even though the letters there are ZQSD, and MDN’s own warning is the flip side, that you cannot use code to tell the user which letter is on the key. keyCode (and its alias which) is the legacy number from before either existed; it is deprecated, varies by browser for punctuation, and cannot distinguish left from right modifiers or a numpad digit from a top-row one without the separate location property (0 standard, 1 left, 2 right, 3 numpad). Modern code reads key or code and ignores keyCode unless it must support very old browsers.
Why keyCode is deprecated
MDN’s description of keyCode is “a system and implementation dependent numerical code identifying the unmodified value of the pressed key”, with the instruction to avoid it and use code or key instead. The problems it names are the ones you will meet in practice. The numbers for letters and digits are consistent (65 to 90 and 48 to 57), but punctuation was never standardised: Firefox historically reported 173 for Minus, 61 for Equal and 59 for Semicolon where other browsers reported 189, 187 and 186. The value describes the “unmodified” key, so Shift-1 and 1 share a keyCode while key tells them apart. Left and right modifiers share a number. Non-US layouts produce numbers that do not match any table, because the number followed the platform’s virtual-key code for whatever character the layout put there. And during input-method composition many browsers report 229 for every key. None of this is fixable inside keyCode, so the UI Events specification replaced it with two well-defined strings. If you maintain old code, this page shows you the keyCode your browser emits today next to the code to migrate to; the table below lists the common pairs.
Full key code table
Values of event.code with the event.key you get on a US layout (unshifted / shifted) and the legacy keyCode as documented by MDN. The key column changes with layout; the code column does not. Browser notes are in the last column.
| event.code | event.key (US layout, unshifted / shifted) | keyCode (legacy) | Notes |
|---|---|---|---|
KeyA | a / A | 65 | |
KeyB | b / B | 66 | |
KeyC | c / C | 67 | |
KeyD | d / D | 68 | |
KeyE | e / E | 69 | |
KeyF | f / F | 70 | |
KeyG | g / G | 71 | |
KeyH | h / H | 72 | |
KeyI | i / I | 73 | |
KeyJ | j / J | 74 | |
KeyK | k / K | 75 | |
KeyL | l / L | 76 | |
KeyM | m / M | 77 | |
KeyN | n / N | 78 | |
KeyO | o / O | 79 | |
KeyP | p / P | 80 | |
KeyQ | q / Q | 81 | |
KeyR | r / R | 82 | |
KeyS | s / S | 83 | |
KeyT | t / T | 84 | |
KeyU | u / U | 85 | |
KeyV | v / V | 86 | |
KeyW | w / W | 87 | |
KeyX | x / X | 88 | |
KeyY | y / Y | 89 | |
KeyZ | z / Z | 90 | |
Digit0 | 0 / ) | 48 | |
Digit1 | 1 / ! | 49 | |
Digit2 | 2 / @ | 50 | |
Digit3 | 3 / # | 51 | |
Digit4 | 4 / $ | 52 | |
Digit5 | 5 / % | 53 | |
Digit6 | 6 / ^ | 54 | |
Digit7 | 7 / & | 55 | |
Digit8 | 8 / * | 56 | |
Digit9 | 9 / ( | 57 | |
Space | " " | 32 | |
Enter | Enter | 13 | |
Tab | Tab | 9 | |
Backspace | Backspace | 8 | |
Escape | Escape | 27 | |
CapsLock | CapsLock | 20 | |
ShiftLeft | Shift | 16 | |
ShiftRight | Shift | 16 | |
ControlLeft | Control | 17 | |
ControlRight | Control | 17 | |
AltLeft | Alt | 18 | |
AltRight | Alt (AltGraph on some layouts) | 18 | |
MetaLeft | Meta | 91 | Mac keyboards: Command reports as Meta |
MetaRight | Meta | 93 | MetaRight: 92 on Windows browsers historically, 93 in Firefox; MDN lists both |
ContextMenu | ContextMenu | 93 | |
ArrowLeft | ArrowLeft | 37 | |
ArrowUp | ArrowUp | 38 | |
ArrowRight | ArrowRight | 39 | |
ArrowDown | ArrowDown | 40 | |
Home | Home | 36 | |
End | End | 35 | |
PageUp | PageUp | 33 | |
PageDown | PageDown | 34 | |
Insert | Insert | 45 | |
Delete | Delete | 46 | |
Pause | Pause | 19 | |
ScrollLock | ScrollLock | 145 | |
NumLock | NumLock | 144 | |
PrintScreen | PrintScreen | 44 (keyup only in most browsers) | |
F1 | F1 | 112 | |
F2 | F2 | 113 | |
F3 | F3 | 114 | |
F4 | F4 | 115 | |
F5 | F5 | 116 | |
F6 | F6 | 117 | |
F7 | F7 | 118 | |
F8 | F8 | 119 | |
F9 | F9 | 120 | |
F10 | F10 | 121 | |
F11 | F11 | 122 | |
F12 | F12 | 123 | |
Backquote | ` / ~ | 192 | |
Minus | - / _ | 189 | Firefox historically 173 |
Equal | = / + | 187 | Firefox historically 61 |
BracketLeft | [ / { | 219 | |
BracketRight | ] / } | 221 | |
Backslash | \\ / | | 220 | |
Semicolon | ; / : | 186 | Firefox historically 59 |
Quote | ' / " | 222 | |
Comma | , / < | 188 | |
Period | . / > | 190 | |
Slash | / / ? | 191 | |
IntlBackslash | \\ / | (ISO key left of Z) | 226 | layout-dependent |
IntlRo | \\ / _ (JIS) | 193 | layout-dependent |
IntlYen | ¥ / | | 255 | layout-dependent |
Numpad0 | 0 | 96 | Num Lock off: navigation key names |
Numpad1 | 1 | 97 | Num Lock off: navigation key names |
Numpad2 | 2 | 98 | Num Lock off: navigation key names |
Numpad3 | 3 | 99 | Num Lock off: navigation key names |
Numpad4 | 4 | 100 | Num Lock off: navigation key names |
Numpad5 | 5 | 101 | Num Lock off: navigation key names |
Numpad6 | 6 | 102 | Num Lock off: navigation key names |
Numpad7 | 7 | 103 | Num Lock off: navigation key names |
Numpad8 | 8 | 104 | Num Lock off: navigation key names |
Numpad9 | 9 | 105 | Num Lock off: navigation key names |
NumpadMultiply | * | 106 | |
NumpadAdd | + | 107 | |
NumpadSubtract | - | 109 | |
NumpadDecimal | . | 110 | |
NumpadDivide | / | 111 | |
NumpadEnter | Enter | 13 | |
AudioVolumeMute | AudioVolumeMute | 173 | media keys: browser and OS dependent, often not delivered |
AudioVolumeDown | AudioVolumeDown | 174 | media keys: browser and OS dependent, often not delivered |
AudioVolumeUp | AudioVolumeUp | 175 | media keys: browser and OS dependent, often not delivered |
MediaPlayPause | MediaPlayPause | 179 | media keys: browser and OS dependent, often not delivered |
MediaTrackNext | MediaTrackNext | 176 | media keys: browser and OS dependent, often not delivered |
MediaTrackPrevious | MediaTrackPrevious | 177 | media keys: browser and OS dependent, often not delivered |
BrowserBack | BrowserBack | 166 | media keys: browser and OS dependent, often not delivered |
BrowserForward | BrowserForward | 167 | media keys: browser and OS dependent, often not delivered |
Handling keyboard layouts and IME
Two situations break naive key handling. Layouts. On a German board the key at the QWERTY Y position types Z, on French AZERTY the key at Q types A, and on Dvorak nearly everything moves. If your handler uses code, physical positions stay put, which is right for game controls and wrong for letter shortcuts: a “press S” hint would point German users at the correct key but French users at the wrong one. If it uses key, letters follow the user’s expectations but positional clusters (WASD) scatter. The usual answer is code for movement and key for commands, and the Keyboard API’s getLayoutMap(), where available, to label a physical code with the character it currently produces. ISO boards add a key that ANSI boards lack, IntlBackslash, next to the left Shift; the ANSI vs ISO guide shows where it is and what it reports. Input method editors. When a user types Japanese, Chinese or Korean, or composes accented characters with dead keys, the keyboard events do not correspond to the text being produced. Browsers report key as Process or Unidentified and keyCode as 229 during composition, and isComposing is true; the text arrives through composition events and input events instead. Handlers that act on keydown must check isComposing and leave those presses alone, and anything that depends on the typed text should listen to the input event rather than reconstruct it from keys. The Dead value of key marks a dead key press that produces nothing on its own.
Copy-ready snippets
The snippet in the frame is rewritten with each key you press; the default pattern is a keydown listener that checks code for the physical key and key for the character, with comments saying which is which, in plain JavaScript or as a React effect with cleanup. A few conventions worth copying along with it: check event.isComposing before acting on keydown; prefer code for anything positional and key for anything textual; use location or the Left/Right codes to tell modifiers apart; never store keyCode in new code; and call preventDefault only for keys you actually handle, so the browser’s shortcuts keep working for everything else. The input tests hub lists the user-facing keyboard tests built on the same events.
Frequently asked questions
What is the difference between event.key and event.code?
key is the character or key name after the keyboard layout and modifiers have been applied: what the user typed. code is the physical key position, the same regardless of layout or Shift. MDN's example: the code KeyQ is the Q key on QWERTY, the ' key on Dvorak and the A key on AZERTY. Use key for text and shortcuts shown to users, code for game-style controls that depend on where a key sits.
Is keyCode deprecated?
Yes. MDN describes keyCode as deprecated and system- and implementation-dependent, and says to use code (physical key) or key (character) instead. keyCode and which still work in current browsers for old code, but values for punctuation differ between browsers and layouts, which is one reason they were replaced.
Why is the keyCode for a punctuation key different in Firefox?
Because keyCode was never standardised for those keys; each browser inherited different platform conventions. The table marks the historical Firefox values for Minus, Equal and Semicolon. event.code avoids the problem entirely: it is Minus, Equal and Semicolon on every browser.
Why does event.code come back empty or Unidentified?
Some virtual keyboards, remote-desktop sessions, accessibility tools and older browsers do not report a physical code. Mobile on-screen keyboards in particular often send key with an empty code, or a key of Unidentified with keyCode 229 while an input method composes text. Handle the missing case: fall back to key, and treat 229 as composition in progress.
How do I detect the left or right Shift key?
Use event.code (ShiftLeft / ShiftRight) or event.location (1 for left, 2 for right, 3 for numpad). event.key is Shift for both. The same applies to Control, Alt and Meta, and to the numpad digits versus the top-row digits, which share a key value but have different codes and locations.