JavaScript Key Code Finder
Press a key in the box to see its event.key, event.code, legacy keyCode and which, location, modifiers and repeat state, with a snippet to copy. The example, Enter, gives event.key “Enter”, event.code “Enter” and keyCode 13, so the check is if (event.key === 'Enter'). Prefer event.key (what the key types) or event.code (which physical key); keyCode and which are deprecated. The table lists 28 common keys. Everything runs in your browser and nothing you press is sent anywhere.
Updated Runs in your browser: nothing you enter is uploadedHow this tool works
Press a key
Click the box or Tab to it, then press any key. Tab leaves the box as usual; to inspect Tab itself, tick the box below. Escape releases it.
Last key
Enter
- event.key
- Enter
- The value the key produces, after layout and modifiers.
- event.code
- Enter
- The physical key, the same whatever the layout.
- event.keyCode
- 13
- Deprecated number. Use key or code.
- event.which
- 13
- Deprecated, usually equal to keyCode.
- event.location
- 0 (Standard)
- Which copy of the key: standard, left, right or numpad.
- Modifiers
- None
- Shift, Ctrl, Alt and Meta held while the key went down.
- event.repeat
- false
- True while the key is held down and auto-repeating.
JavaScript to copy
if (event.key === 'Enter')if (event.code === 'Enter')if (event.keyCode === 13)Recent keys
No keys pressed yet. Each entry reads key · code · keyCode, newest first.
Common keys: event.key, event.code and keyCode
| Key | event.key | event.code | keyCode (legacy) | Note |
|---|---|---|---|---|
| Enter (main) | Enter | Enter | 13 | Typical value |
| Enter (numpad) | Enter | NumpadEnter | 13 | Same key and keyCode as main Enter; code and location differ. |
| Space | " " (a space) | Space | 32 | Typical value |
| Tab | Tab | Tab | 9 | Typical value |
| Escape | Escape | Escape | 27 | Typical value |
| Backspace | Backspace | Backspace | 8 | Typical value |
| Delete | Delete | Delete | 46 | Typical value |
| Insert | Insert | Insert | 45 | Typical value |
| Arrow up | ArrowUp | ArrowUp | 38 | Typical value |
| Arrow down | ArrowDown | ArrowDown | 40 | Typical value |
| Arrow left | ArrowLeft | ArrowLeft | 37 | Typical value |
| Arrow right | ArrowRight | ArrowRight | 39 | Typical value |
| Home | Home | Home | 36 | Typical value |
| End | End | End | 35 | Typical value |
| Page Up | PageUp | PageUp | 33 | Typical value |
| Page Down | PageDown | PageDown | 34 | Typical value |
| Shift (left) | Shift | ShiftLeft | 16 | The right Shift has code ShiftRight and the same keyCode. |
| Control (left) | Control | ControlLeft | 17 | Typical value |
| Alt (left) | Alt | AltLeft | 18 | Typical value |
| Meta (left) | Meta | MetaLeft | 91 | The Windows or Command key. On Windows the right Windows key is 92 (code MetaRight); Firefox on macOS reports 224 for both Command keys. |
| Caps Lock | CapsLock | CapsLock | 20 | Typical value |
| Context menu | ContextMenu | ContextMenu | 93 | Typical value |
| F1 | F1 | F1 | 112 | Typical value |
| F12 | F12 | F12 | 123 | Typical value |
| Letter A | a | KeyA | 65 | event.key is “A” with Shift or Caps Lock; code and keyCode do not change. |
| Digit 1 (top row) | 1 | Digit1 | 49 | Typical value |
| Numpad 1 (Num Lock on) | 1 | Numpad1 | 97 | Same event.key as the top row; code, keyCode and location tell them apart. |
| Slash | / | Slash | 191 | Typical value |
event.location values
| Value | Name | Meaning |
|---|---|---|
| 0 | Standard | The key has one copy on the keyboard (letters, digits, Enter, Space). |
| 1 | Left | The left copy of a key that exists twice (Shift, Control, Alt, Meta). |
| 2 | Right | The right copy of a key that exists twice. |
| 3 | Numpad | A key on the numeric keypad (including its Enter and the digits with Num Lock on). |
How to find a JavaScript key code
- Focus the capture box. Click the box or Tab to it. It says “Listening” while it has focus.
- Press a key. The result shows event.key, event.code, keyCode, which, location, modifiers and repeat. Hold Shift, Ctrl, Alt or Meta to see them reported.
- Copy the snippet. Choose the event.key or event.code line and copy it into your keydown handler. Use the keyCode line only for old code you cannot change.
- Leave the box. Press Tab to move on. To inspect Tab itself, turn on “Capture Tab and browser keys”; Escape or unticking the box releases it again.
Frequently asked questions
- Is keyCode deprecated?
- Yes. keyCode, charCode and which are legacy properties: the UI Events specification keeps them only for compatibility with old content and does not define their values, and MDN marks them deprecated. Browsers still send them, so old code works, but new code should use event.key or event.code.
- What is the difference between event.key and event.code?
- event.key is the value the key produces, taking the keyboard layout, Shift and Caps Lock into account: “a”, “A”, “Enter”, “ArrowUp”. event.code names the physical key and ignores layout: pressing the key right of Tab on a French AZERTY keyboard gives key “a” but code “KeyQ”. Use key for text-like shortcuts and code for game controls such as WASD.
- What is the keyCode for Enter?
- 13. Main Enter and numpad Enter both report keyCode 13 and event.key “Enter”; event.code is “Enter” for the main key and “NumpadEnter” for the keypad, and event.location is 0 and 3.
- How do I tell the left and right Shift apart?
- Use event.code (“ShiftLeft” or “ShiftRight”) or event.location (1 for left, 2 for right). event.key is “Shift” for both and keyCode is 16 for both.
- Why does a phone or tablet show keyCode 229 or “Unidentified”?
- On-screen keyboards and input method editors (IME) often compose text instead of sending one event per key, so browsers report keyCode 229 or event.key “Unidentified”. Listen to the input or beforeinput event for text instead of keydown.
- Why does pressing Tab leave the capture box?
- The box must not trap keyboard users, so by default Tab moves focus as usual after it is recorded. Turn on “Capture Tab and browser keys” to keep focus and inspect Tab; Escape (which is recorded first) or unticking the box releases the capture.
- Why are some shortcuts not reported?
- The browser or operating system handles some shortcuts, such as Ctrl+W, Ctrl+T, Alt+Tab or the Windows key, before the page sees them, and a page cannot receive them. Keys the page does receive appear here.
- Which keydown, keypress and keyup event should I use?
- Use keydown for shortcuts and keyup for “released” logic. keypress is deprecated and does not fire for many keys. This tool reads keydown, which fires for every key including modifiers and auto-repeats while the key is held (event.repeat is true).
How it works
The tool listens for keydown on the capture box and copies the fields of the KeyboardEvent: key, code, keyCode, which, location, the four modifier flags and repeat. Snippets are built from those values and quote them as JavaScript strings, appending a check for each modifier that was held. The result is whatever your browser, operating system and keyboard layout report, so the same physical key can give a different event.key on another layout. The table of common keys shows typical values on a US QWERTY keyboard: event.key and event.code names follow the W3C UI Events key and code specifications, while keyCode numbers are de facto legacy values, not defined by a specification. Auto-repeat events update the result but are not added to the history, which keeps the last eight keys. Nothing you press is stored or sent; analytics record only that the tool was used.
Sources
More free tools
- Unicode Character InspectorPaste text to see every character: graphemes, code points, UTF-8 and UTF-16, escapes, category, script, hidden characters and look-alike letters.
- Typing Speed TestFree typing speed test for 30 seconds, 60 seconds or 2 minutes: live WPM, net WPM, accuracy and characters per minute, with the scoring formulas shown.
- User Agent ParserPaste a User-Agent string to see the browser and version, rendering engine, OS, device type and notable tokens. Explains UA reduction. Runs locally.
- Robots.txt Generator and TesterBuild a robots.txt with per-crawler rules, wildcards and sitemaps, then test any URL path against it as RFC 9309 says a crawler must. Runs in your browser.
- UTM BuilderAdd utm_source, utm_medium and utm_campaign to any link with correct encoding, check case and spaces, read a tagged URL back, or tag a whole list at once.
- Favicon GeneratorMake a favicon from an image, text or an emoji: PNGs from 16 to 512 px, favicon.ico, an SVG icon, the HTML link tags and a ZIP. Runs in your browser.
More: Web, URLs, images and networkAll developer toolsAll toolsHome & DIY calculators