Keycode Finder
Press any key to see its JavaScript key event values
Press any key
—
Common Keys Reference
| Key | Code | keyCode | Description |
|---|
Press any key and instantly see everything the browser reports about it: event.key, event.code, the legacy event.which and event.keyCode numbers, and which modifiers (Ctrl, Shift, Alt, Meta) were held. Below the live display, a searchable reference table lists the key, code, and legacy keyCode values for letters, digits, function keys, arrows, and more. The capture is in-page and local, so keystrokes are read from the event object without being logged or sent anywhere.
Reading the Live Display
Click the page so it has focus, then press a key. The large panel shows event.key — the value the key produced. Three cards beneath it break down event.code (the physical key), event.which, and event.keyCode. Four badges for Ctrl, Shift, Alt, and Meta light up whenever the corresponding modifier flag is true during that keypress.
Try a few deliberate combinations to see how the values diverge. Press a, then Shift+A: the key changes from a to A, but the code stays KeyA and keyCode stays 65. Press the spacebar and event.key is a single space character rather than the word “Space”, while event.code is Space and keyCode is 32. This makes the tool useful for confirming exactly what a handler will receive before you write branching logic.
event.key vs event.code vs keyCode
Modern code should branch on event.key when it cares about meaning (“did the user press Enter?”) and on event.code when it cares about physical position (“the WASD cluster, whatever the layout”). The numeric keyCode and which properties are deprecated but still appear in legacy libraries and older answers, so this tool shows them side by side.
For printable characters, keyCode reflects the unshifted uppercase value: a and Shift+A both report 65, and 1 and Shift+1 both report 49 even though the latter produces !. event.key gives you the exact character, so it is the right choice for text entry. event.code ignores shift and layout entirely, which is why it is the safe choice for game controls on international keyboards.
Worked Example: Wiring a Ctrl+K Shortcut
Suppose you want a “command palette” hotkey. Hold Ctrl and press k. The display shows:
| Property | Value |
|---|---|
| event.key | k |
| event.code | KeyK |
| event.keyCode / which | 75 |
| event.ctrlKey | true |
A handler such as if (e.ctrlKey && e.key === 'k') { openPalette(); } will match, and the keyCode card confirms the legacy 75 if you need to support an older library. Now compare a WASD movement scheme: on an AZERTY keyboard the key labelled Z sits where a US W is, so event.key becomes z while event.code still reports KeyW. Branching on event.code keeps movement consistent across layouts; branching on event.key does not.
Function keys follow the same pattern: F1 is code F1 with keyCode 112, and the sequence runs up to F12 at 123. Arrow keys are codes ArrowUp (38), ArrowDown (40), ArrowLeft (37), and ArrowRight (39).
Choosing the Right Property
| Task | Read | Why |
|---|---|---|
| Text input or validation | event.key | Gives the exact character, including Shift and dead-key results |
| Game movement or layout-independent shortcuts | event.code | Tracks physical position regardless of keyboard layout |
| Migrating legacy code | event.keyCode | Matches numbers older libraries still expect |
| Detecting a modifier held with another key | event.ctrlKey, event.shiftKey, event.altKey, event.metaKey | Reports state on the keydown event itself |
A robust shortcut often combines both: check event.code for the physical key and a modifier flag for the chord, rather than string-matching event.key.
Common Mistakes
- Using keyCode for text input. It cannot distinguish
afromAor1from!, so validation and character handling break. - Using event.key for game controls. Layout and Shift change the value, so the same physical key stops working on non-US keyboards.
- Assuming the modifier key itself has a printable value. Pressing Shift alone reports
keyasShift; the useful signal is theshiftKeyflag on the next key. - Forgetting to call preventDefault. For keys like Tab or the spacebar, the browser’s default action still runs and can scroll or move focus unless you suppress it.
- Expecting reserved shortcuts to arrive. Ctrl+W, Ctrl+T, Alt+Tab, and F12 are handled by the browser or OS and never reach your listener.
What the Reference Table Covers
The searchable table below the live display lists the US-layout values for the letters A–Z, digits 0–9, function keys F1–F12, arrow and navigation keys, editing keys such as Enter and Backspace, the modifier and lock keys, common punctuation, and the full numpad. Each row carries a short plain-language description, and the search box matches on key, code, description, or category — type numpad, arrow, or F5 to filter. It is the fallback when you need a value you cannot press right now, such as a key missing from a laptop keyboard. Searching letter returns all 26 letter rows, punctuation returns the bracket, quote, and slash keys with their codes, and KeyA returns the single row for the A key with keyCode 65.
Related Tools
Frequently Asked Questions
Why does pressing Shift+A report key A but keyCode 65?
event.key reflects the character the keystroke produces, so Shift+A gives an uppercase A while plain a gives lowercase a. The legacy keyCode is layout-and-shift independent for printable keys: both a and Shift+A report 65. That difference is exactly why keyCode is unreliable for character input.
What is the difference between event.which and event.keyCode?
In modern browsers they return the same number for a keyboard event — which is a legacy alias of keyCode — and this tool displays both side by side so you can confirm. Neither is standardized for new code; prefer event.key for meaning and event.code for physical position.
Why can I not capture Alt+Tab or Ctrl+W in the tool?
Operating-system and browser-level shortcuts never reach the page. Alt+Tab is intercepted by the OS, and Ctrl+W closes the tab before any script sees the event. The live display only shows keys the browser actually delivers, which is why some combinations appear to do nothing.
How do I detect the Windows or Command key as a modifier?
Check event.metaKey. It is true while the Windows key on PCs or the Command key on macOS is held. The physical key itself reports event.code MetaLeft (91) or MetaRight (92), and the live display lights the Meta badge when it is pressed with another key.
Why does the numpad Enter key show a different code than the main Enter key?
They are different physical keys, so event.code distinguishes them as NumpadEnter and Enter even though both produce event.key Enter and keyCode 13. If your shortcut should react to either, branch on event.key rather than event.code.
Can the page capture keystrokes I type in another tab or app?
No. The listener only fires while the tool's page has focus, and keystrokes are read from the in-page key event without being stored or transmitted. Switch to another tab or application and the capture stops.
Reviewed by the HandyTools Hub team · Last updated