Free tool
JavaScript keycode finder
Press any key to see the values a JavaScript keyboard event carries: event.key, event.code, the legacy keyCode and which, the key's location and which modifiers were held. You also get a keydown handler to paste, an event log and a table of every key.
Free · no sign-up · runs in your browser, nothing is uploaded
Press a key on your keyboard
The values show up here as soon as the browser fires keydown.
Press a key to get a keydown listener for it.
Every keydown (and keyup, if you turn it on) is listed here, newest first.
| Key | keyCode | event.key | event.code |
|---|---|---|---|
| 8 | "Backspace" | Backspace | |
| 9 | "Tab" | Tab | |
| 13 | "Enter" | Enter | |
| 16 | "Shift" | ShiftLeft | |
| 16 | "Shift" | ShiftRight | |
| 17 | "Control" | ControlLeft | |
| 17 | "Control" | ControlRight | |
| 18 | "Alt" | AltLeft | |
| 18 | "Alt" | AltRight | |
| 19 | "Pause" | Pause | |
| 20 | "CapsLock" | CapsLock | |
| 27 | "Escape" | Escape | |
| 32 | " " | Space | |
| 33 | "PageUp" | PageUp | |
| 34 | "PageDown" | PageDown | |
| 35 | "End" | End | |
| 36 | "Home" | Home | |
| 37 | "ArrowLeft" | ArrowLeft | |
| 38 | "ArrowUp" | ArrowUp | |
| 39 | "ArrowRight" | ArrowRight | |
| 40 | "ArrowDown" | ArrowDown | |
| 44 | "PrintScreen" | PrintScreen | |
| 45 | "Insert" | Insert | |
| 46 | "Delete" | Delete | |
| 48 | "0" | Digit0 | |
| 49 | "1" | Digit1 | |
| 50 | "2" | Digit2 | |
| 51 | "3" | Digit3 | |
| 52 | "4" | Digit4 | |
| 53 | "5" | Digit5 | |
| 54 | "6" | Digit6 | |
| 55 | "7" | Digit7 | |
| 56 | "8" | Digit8 | |
| 57 | "9" | Digit9 | |
| 65 | "a" | KeyA | |
| 66 | "b" | KeyB | |
| 67 | "c" | KeyC | |
| 68 | "d" | KeyD | |
| 69 | "e" | KeyE | |
| 70 | "f" | KeyF | |
| 71 | "g" | KeyG | |
| 72 | "h" | KeyH | |
| 73 | "i" | KeyI | |
| 74 | "j" | KeyJ | |
| 75 | "k" | KeyK | |
| 76 | "l" | KeyL | |
| 77 | "m" | KeyM | |
| 78 | "n" | KeyN | |
| 79 | "o" | KeyO | |
| 80 | "p" | KeyP | |
| 81 | "q" | KeyQ | |
| 82 | "r" | KeyR | |
| 83 | "s" | KeyS | |
| 84 | "t" | KeyT | |
| 85 | "u" | KeyU | |
| 86 | "v" | KeyV | |
| 87 | "w" | KeyW | |
| 88 | "x" | KeyX | |
| 89 | "y" | KeyY | |
| 90 | "z" | KeyZ | |
| 91Firefox on Mac: 224 | "Meta" | MetaLeft | |
| 92Firefox 91Mac: 93 in Chrome and Safari, 224 in Firefox | "Meta" | MetaRight | |
| 93 | "ContextMenu" | ContextMenu | |
| 96 | "0" | Numpad0 | |
| 97 | "1" | Numpad1 | |
| 98 | "2" | Numpad2 | |
| 99 | "3" | Numpad3 | |
| 100 | "4" | Numpad4 | |
| 101 | "5" | Numpad5 | |
| 102 | "6" | Numpad6 | |
| 103 | "7" | Numpad7 | |
| 104 | "8" | Numpad8 | |
| 105 | "9" | Numpad9 | |
| 106 | "*" | NumpadMultiply | |
| 107 | "+" | NumpadAdd | |
| 13 | "Enter" | NumpadEnter | |
| 109 | "-" | NumpadSubtract | |
| 110 | "." | NumpadDecimal | |
| 111 | "/" | NumpadDivide | |
| 112 | "F1" | F1 | |
| 113 | "F2" | F2 | |
| 114 | "F3" | F3 | |
| 115 | "F4" | F4 | |
| 116 | "F5" | F5 | |
| 117 | "F6" | F6 | |
| 118 | "F7" | F7 | |
| 119 | "F8" | F8 | |
| 120 | "F9" | F9 | |
| 121 | "F10" | F10 | |
| 122 | "F11" | F11 | |
| 123 | "F12" | F12 | |
| 144 | "NumLock" | NumLock | |
| 145 | "ScrollLock" | ScrollLock | |
| 186Firefox 59 | ";" | Semicolon | |
| 187Firefox 61 | "=" | Equal | |
| 188 | "," | Comma | |
| 189Firefox 173 | "-" | Minus | |
| 190 | "." | Period | |
| 191 | "/" | Slash | |
| 192 | "`" | Backquote | |
| 219 | "[" | BracketLeft | |
| 220 | "\\" | Backslash | |
| 221 | "]" | BracketRight | |
| 222 | "'" | Quote |
104 keys, US QWERTY layout. keyCode values are what Chrome, Edge and Safari send.
event.key vs event.code vs keyCode
Each keyboard event describes the same key press three ways. Here is what you get for a few presses on US and French keyboards:
| Press | event.key | event.code | keyCode |
|---|---|---|---|
| A (US layout) | "a" | "KeyA" | 65 |
| Shift + A | "A" | "KeyA" | 65 |
| Shift + 1 (US layout) | "!" | "Digit1" | 49 |
| The A key on a French AZERTY keyboard | "q" | "KeyA" | 81 |
| Enter on the numpad | "Enter" | "NumpadEnter" | 13 |
| Left Shift | "Shift" | "ShiftLeft" | 16 |
key follows the layout and modifiers, so it is right for text and letter shortcuts. code names the physical key after its spot on a US QWERTY board, so it is right for game controls that should stay in place on any layout. keyCode is a legacy number that differs between browsers and layouts; read it only to support old code.
Listen for keys in JavaScript
A shortcut handler that works on Windows, Linux and Mac, and stays out of the way while people type in a form:
document.addEventListener('keydown', (event) => {
if (event.isComposing) return; // IME is composing text
const t = event.target;
if (t.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(t.tagName)) return;
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'k') {
event.preventDefault(); // stop the browser's own Ctrl+K
openSearch();
}
if (event.key === 'Escape') closeDialog();
if (event.code === 'KeyW' && !event.repeat) moveForward(); // physical key, ignore auto-repeat
});React passes the same values on its synthetic event: onKeyDown={e => e.key === 'Enter' && submit()}. Press a key in the tool above and the Handler for this key panel writes this check for you, matching on key or code.
keyCode list for common keys
| Key | event.key | event.code | keyCode |
|---|---|---|---|
| Enter | "Enter" | Enter | 13 |
| Esc | "Escape" | Escape | 27 |
| Space | " " | Space | 32 |
| Tab | "Tab" | Tab | 9 |
| Backspace | "Backspace" | Backspace | 8 |
| Delete | "Delete" | Delete | 46 |
| Shift (left) | "Shift" | ShiftLeft | 16 |
| Ctrl (left) | "Control" | ControlLeft | 17 |
| Alt / Option (left) | "Alt" | AltLeft | 18 |
| Windows / Command (left) | "Meta" | MetaLeft | 91 |
| Left arrow | "ArrowLeft" | ArrowLeft | 37 |
| Up arrow | "ArrowUp" | ArrowUp | 38 |
| Right arrow | "ArrowRight" | ArrowRight | 39 |
| Down arrow | "ArrowDown" | ArrowDown | 40 |
| Home | "Home" | Home | 36 |
| End | "End" | End | 35 |
| PageUp | "PageUp" | PageUp | 33 |
| PageDown | "PageDown" | PageDown | 34 |
| A to Z | "a" to "z" | KeyA to KeyZ | 65 to 90 |
| 0 to 9 (top row) | "0" to "9" | Digit0 to Digit9 | 48 to 57 |
| Numpad 0 to 9 | "0" to "9" | Numpad0 to Numpad9 | 96 to 105 |
| F1 to F12 | "F1" to "F12" | F1 to F12 | 112 to 123 |
The letter keyCodes match the uppercase ASCII codes (A is 65 in both), and the top-row digits match ASCII "0" to "9". See the ASCII table for the rest. The full table with punctuation, numpad and modifier keys is in the tool above, and it downloads as CSV.
Gotchas with keyboard events
- Firefox numbers differ. MDN lists Firefox keyCodes of 59 for
;, 61 for=and 173 for-, where Chrome and Safari send 186, 187 and 189. Matching onevent.keyavoids this. - AltGr is Ctrl + Alt on Windows. Typing
@or€with AltGr on many European layouts sets bothctrlKeyandaltKey, so a Ctrl+Alt shortcut can fire while someone types.event.getModifierState('AltGraph')tells them apart. - Dead keys. Keys that start an accent (like
´on many layouts) reportevent.key === 'Dead'. The finished character comes with the next key press. - Left and right.
event.locationis 1 for the left Shift, Ctrl, Alt or Meta, 2 for the right one, 3 for the numpad and 0 for everything else.event.codealso says it:ShiftLeft,ShiftRight. - Some shortcuts never reach the page. Browsers keep Ctrl/⌘ + W, T and N for themselves, and the OS takes Alt+Tab and Alt+F4 on Windows. The tool above warns you when you press one.
- Phones are different. Many on-screen keyboards send
keyCode229 andkey"Unidentified" for letters. Read the input's value in aninputevent instead.
Replace keyCode with event.key
Old code that compares numbers maps directly to key names:
// before // after if (e.keyCode === 13) submit(); if (e.key === 'Enter') submit(); if (e.keyCode === 27) close(); if (e.key === 'Escape') close(); if (e.keyCode === 32) toggle(); if (e.key === ' ') toggle(); if (e.which === 37) prev(); if (e.key === 'ArrowLeft') prev(); if (e.keyCode >= 48 && e.keyCode <= 57) digit(); if (/^[0-9]$/.test(e.key)) digit();
Old browsers sent "Esc", "Left" and "Spacebar" (IE and old Edge), so if you must support them, check both names. For other browser details, see what is my user agent, which parses your browser, OS and client hints. More testing tools are in the testing tools directory.
More free developer tools
FAQ
What is the keyCode for Enter?+
event.keyCode is 13 for Enter, both the main Enter key and the numpad one. In modern code, check event.key === "Enter" instead. To tell the two keys apart, use event.code: "Enter" for the main key and "NumpadEnter" for the numpad.
Is keyCode deprecated?+
Yes. MDN marks KeyboardEvent.keyCode and which as deprecated: the numbers depend on the browser, the operating system and the keyboard layout. Browsers still support them so old code keeps working, but new code should use event.key (the character or key name) or event.code (the physical key).
What is the difference between event.key and event.code?+
event.key is what the key produces with the current layout and modifiers: "a", "A" with Shift, "q" on a French AZERTY keyboard, or a name like "Enter". event.code is the physical key position, named after a US QWERTY keyboard, so the same key is always "KeyA" whatever the layout. Use key for text and shortcuts with letters, code for game controls like WASD.
What are the keyCodes for the arrow keys?+
Left is 37, Up is 38, Right is 39 and Down is 40. Their event.key and event.code values are "ArrowLeft", "ArrowUp", "ArrowRight" and "ArrowDown". Arrow keys scroll the page by default, so call event.preventDefault() if you handle them yourself.
How do I detect Ctrl or Cmd + a key in JavaScript?+
Check the modifier flags on the keydown event: if ((event.ctrlKey || event.metaKey) && event.key === "k"). On a Mac, Command sets metaKey and Option sets altKey. With Shift held, event.key for a letter is uppercase, so compare with event.key.toLowerCase() or use event.code === "KeyK".
Why is keyCode 229?+
keyCode 229 means an input method editor (IME) is composing text: typing Chinese, Japanese or Korean, using some Android keyboards, or holding a key for an accented character. During composition, event.isComposing is true. Ignore those key events, or listen for input and compositionend instead.
Should I use keydown, keyup or keypress?+
Use keydown for shortcuts and controls: it fires for every key, repeats while the key is held (event.repeat is true) and can be cancelled with preventDefault(). Use keyup when an action should happen on release. keypress is deprecated and does not fire for keys that produce no character, such as arrows or Escape.
What is the keyCode for the space bar?+
The space bar has keyCode 32. Its event.key is a single space " " (not "Space"), and its event.code is "Space". Space scrolls the page and presses a focused button, so only call preventDefault() when you really handle it.
Sources: W3C UI Events KeyboardEvent key values · W3C UI Events KeyboardEvent code values · MDN: KeyboardEvent · MDN: KeyboardEvent.keyCode · MDN: Code values for keyboard events · MDN: KeyboardEvent.isComposing. Checked 2026-10-31.