JavaScript Keycode Finder

Press any key to get its JavaScript keycode, event.key and event.code. Shortcut code, an event log and the full key codes list for Enter, Space, Escape, arrows and more.

How to use the keycode finder

  1. Press any key. You get its keyCode in large type, plus event.key, event.code, event.which, event.location and the modifier keys. Click any value to copy it.
  2. Press a shortcut like Ctrl+Shift+K or ⌘K to get its label and the if check to paste into your keydown handler.
  3. Watch the event log to see keydown, keypress and keyup in the order they fire, with the time between them and when repeat turns true.
  4. Look up a key you can’t press, like F5 or a numpad key, by name, by event.code or by number: search 13 to find Enter.

On a phone, tap the test field to open the keyboard. Your keys never leave the page.

JavaScript key codes list

Every key on a US QWERTY keyboard, with the values a keydown event gives you. event.key is the unshifted character: with Shift held, the A key gives "A" instead of "a".

Key event.key event.code keyCode
Backspace Backspace Backspace 8
Tab Tab Tab 9
Enter Enter Enter 13
Shift Shift ShiftLeft 16
Control Control ControlLeft 17
Alt Alt AltLeft 18
Pause Pause Pause 19
Caps Lock CapsLock CapsLock 20
Escape Escape Escape 27
Space " " Space 32
Page Up PageUp PageUp 33
Page Down PageDown PageDown 34
End End End 35
Home Home Home 36
Left arrow ArrowLeft ArrowLeft 37
Up arrow ArrowUp ArrowUp 38
Right arrow ArrowRight ArrowRight 39
Down arrow ArrowDown ArrowDown 40
Insert Insert Insert 45
Delete Delete Delete 46
0 0 Digit0 48
1 1 Digit1 49
2 2 Digit2 50
3 3 Digit3 51
4 4 Digit4 52
5 5 Digit5 53
6 6 Digit6 54
7 7 Digit7 55
8 8 Digit8 56
9 9 Digit9 57
A a KeyA 65
B b KeyB 66
C c KeyC 67
D d KeyD 68
E e KeyE 69
F f KeyF 70
G g KeyG 71
H h KeyH 72
I i KeyI 73
J j KeyJ 74
K k KeyK 75
L l KeyL 76
M m KeyM 77
N n KeyN 78
O o KeyO 79
P p KeyP 80
Q q KeyQ 81
R r KeyR 82
S s KeyS 83
T t KeyT 84
U u KeyU 85
V v KeyV 86
W w KeyW 87
X x KeyX 88
Y y KeyY 89
Z z KeyZ 90
Meta (Windows / ⌘) Meta MetaLeft 91
Context menu ContextMenu ContextMenu 93
Numpad 0 0 Numpad0 96
Numpad 1 1 Numpad1 97
Numpad 2 2 Numpad2 98
Numpad 3 3 Numpad3 99
Numpad 4 4 Numpad4 100
Numpad 5 5 Numpad5 101
Numpad 6 6 Numpad6 102
Numpad 7 7 Numpad7 103
Numpad 8 8 Numpad8 104
Numpad 9 9 Numpad9 105
Numpad * * NumpadMultiply 106
Numpad + + NumpadAdd 107
Numpad – - NumpadSubtract 109
Numpad . . NumpadDecimal 110
Numpad / / NumpadDivide 111
Numpad Enter Enter NumpadEnter 13
F1 F1 F1 112
F2 F2 F2 113
F3 F3 F3 114
F4 F4 F4 115
F5 F5 F5 116
F6 F6 F6 117
F7 F7 F7 118
F8 F8 F8 119
F9 F9 F9 120
F10 F10 F10 121
F11 F11 F11 122
F12 F12 F12 123
Num Lock NumLock NumLock 144
Scroll Lock ScrollLock ScrollLock 145
Semicolon ; Semicolon 186
Equals = Equal 187
Comma , Comma 188
Minus - Minus 189
Period . Period 190
Slash / Slash 191
Backtick ` Backquote 192
Left bracket [ BracketLeft 219
Backslash \ Backslash 220
Right bracket ] BracketRight 221
Quote ' Quote 222

Firefox uses different keyCode values for some punctuation: Semicolon is 59, Equals is 61 and Minus is 173. The right Windows key is 92 and the right ⌘ key on a Mac is 93 in Chrome. event.key and event.code are the same in every modern browser.

event.key vs event.code vs keyCode

Property What it tells you Use it for
event.key The character or key name the user typed: "a", "A", "Enter", "ArrowUp". It follows the keyboard layout and Shift. Almost everything: Enter to submit, Escape to close, shortcuts by letter
event.code The physical key, named after its spot on a US keyboard: "KeyA", "Digit1", "Space". It ignores layout and Shift. Games and controls tied to a position, like WASD
event.keyCode A number per key. Deprecated: it’s inconsistent across layouts and browsers, but every browser still supports it. Old code only. Replace keyCode === 13 with key === 'Enter'

On a French AZERTY keyboard, the key in the Q spot types “a”: event.key is "a", event.code is "KeyQ". Press it in the tool above with your own layout to see the difference.

Detect the Enter key

Check e.key instead of keyCode === 13. The isComposing check matters for Chinese, Japanese and Korean input: users press Enter to confirm a word, and that shouldn’t send the message.

javascript
input.addEventListener('keydown', (e) => {
    if (e.key === 'Enter' && !e.isComposing) {
        e.preventDefault();
        send();
    }
});

Add a keyboard shortcut that ignores text fields

Skip the shortcut while the user is typing, or pressing K in a search box opens the search again. Check both metaKey and ctrlKey so it’s ⌘K on a Mac and Ctrl+K everywhere else.

javascript
document.addEventListener('keydown', (e) => {
    if (e.target.closest('input, textarea, select, [contenteditable]')) return;

    if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
        e.preventDefault();
        openSearch();
    }
});

Track held keys for games

Store e.code, not e.key: the movement keys stay in the same place on any layout, and Shift doesn’t turn "w" into "W". Clear the set on blur, or a key released while the tab was in the background stays “held”.

javascript
const pressed = new Set();

addEventListener('keydown', (e) => pressed.add(e.code));
addEventListener('keyup', (e) => pressed.delete(e.code));
addEventListener('blur', () => pressed.clear());

// In your game loop: the same physical keys on QWERTY, AZERTY and Dvorak
if (pressed.has('KeyW')) moveUp();
if (pressed.has('KeyA')) moveLeft();

FAQ

What is the keycode for Enter?

13. The Enter key on the numpad is also 13; tell them apart with event.code: "Enter" or "NumpadEnter".

What are the keycodes for Space, Escape, Tab and Backspace?

Space is 32, Escape is 27, Tab is 9 and Backspace is 8. The arrow keys are 37 (left), 38 (up), 39 (right) and 40 (down).

Is keyCode deprecated?

Yes. keyCode, which and charCode are all deprecated in favour of event.key and event.code. Browsers still support them, so old code keeps working, but new code shouldn’t use them.

Why does my phone give keyCode 229?

Mobile keyboards and input methods (IME) handle keys before the page sees them, so most keydown events report keyCode 229 and key "Unidentified". Read the typed text from the beforeinput or input event instead. Try it in the test field above.

Why can’t I catch Ctrl+W or Ctrl+T?

Browsers keep a few shortcuts for themselves, like Ctrl+W, Ctrl+T and Ctrl+N (⌘W, ⌘T and ⌘N on a Mac). The page never receives them, so pick a different combination.

Are Java key codes the same as JavaScript key codes?

Mostly. Java’s KeyEvent constants match for letters (VK_A is 65), digits, Space, Escape, Tab, Backspace and the arrow keys. Two common ones differ: VK_ENTER is 10 (JavaScript: 13) and VK_DELETE is 127 (JavaScript: 46).

Did you like this tool? Share it with your friends:
Want to learn more? Ask your AI: