JavaScript Keycode Finder – event.key and event.code
Press any key on your keyboard to see exactly what JavaScript receives: key, code, keyCode and more.
Code snippet
// Press a key to see a snippet
History
| key | code | keyCode | Modifiers |
|---|
How to use the Keycode Finder
- Press a keyPress any key or key combination. On a phone, tap the dark box first to bring up the keyboard focus.
- Read the valuesSee event.key (the character or key name), event.code (the physical key), the old keyCode and which numbers, the location (left, right, numpad) and the modifier keys held.
- Copy the snippetCopy a ready-made keydown listener for that key. Tick the option to stop browser shortcuts like Tab or Ctrl+S while you test.
Example
Pressing Enter shows key "Enter", code "Enter" and keyCode 13. The numpad Enter has the same key but code "NumpadEnter" and location 3.
Pressing Shift + A shows key "A" (capital), code "KeyA" and keyCode 65, with Shift in the modifiers.
Frequently asked questions
Should I use event.key, event.code or keyCode?
Use event.key when you care about the character typed (it follows the user’s keyboard layout). Use event.code for physical positions, such as WASD in games. keyCode and which are deprecated and kept only for old code.
Why are Ctrl, Shift and Alt shown separately?
They are modifier keys. Each key event tells you whether they were held with ctrlKey, shiftKey, altKey and metaKey (the Windows or Command key).
Why does nothing happen for some keys?
The operating system or browser may capture some combinations before the page sees them, such as Ctrl+W, Alt+Tab or the Windows key.