Keycode Finder

A keycode finder for developers: press any key and see its event.key, event.code, the deprecated keyCode and which, the location value and the modifier state, each with a one-click copy, plus a history of the last ten keys and a JavaScript or React snippet filled in with the key you pressed. Below the tool is a full key code table you can filter, and a plain explanation of why key and code exist, when to use which, and what breaks on non-US layouts and with input method editors.

Click here, then press any key

—

Result class: Measured

event.key
—The character or key name after layout and modifiers (what the user typed).
event.code
—The physical key position, independent of layout and modifiers.
event.keyCode
—Legacy numeric code. Deprecated; kept for old code.
event.which
—Legacy alias of keyCode. Deprecated.
event.location
—0 standard · 1 left · 2 right · 3 numpad.
Modifiers
—ctrlKey · shiftKey · altKey · metaKey · repeat
    JavaScript
    document.addEventListener('keydown', (e) => {
      if (e.code === 'KeyA') {
        // physical key, any layout
      }
      if (e.key === 'a') {
        // typed "a", layout-dependent
      }
    });
    — — Hz

    Runs in your browser. Nothing is uploaded.

    How to use

    1. Click the frame and press a key. The card shows event.key, event.code, keyCode, which and location, with the modifier state; the big label is the code (or the key when the browser gives no code).
    2. Copy any value with the button next to it, or copy the snippet, which uses the last key you pressed in a keydown handler; switch between JavaScript and React in Settings.
    3. Use the filter box under the table to find a key by name, code or number; the table is static, so it is searchable by your browser's find as well.
    4. Turn off "Prevent default actions" in Settings if you want keys like Tab or F5 to behave normally while the frame is focused; by default the page swallows them so you can read their values.

    Press a key to get its code

    Click inside the frame and press any key; the card fills with the five values a keyboard event carries and the modifier state, and the big label shows the code. Each value has a copy button, the last ten keys collect underneath, and the snippet at the bottom is rewritten with the key you just pressed, in JavaScript or React. Everything comes directly from the browser’s KeyboardEvent, so the result class is Measured, and the values are exactly what your own handler would receive in this browser on this operating system, which is the point: a key code table tells you what a key should report, this page tells you what it does report here. By default the page prevents the browser’s own actions for the keys you press while it has focus, so Tab stays in the frame and F5 does not reload; Settings turns that off. The keyboard tester shows the same codes for every key in its event log if you want to see a whole board at once, and the Mac keyboard tester does the same with Apple’s key names.

    event.key vs event.code vs keyCode

    Three properties describe one key press, and they answer different questions. event.key answers “what did the user type?”: a character (“a”, “A”, “é”, “ß”) or a named key (“Enter”, “ArrowLeft”, “Shift”), after the operating system’s keyboard layout, dead keys and modifiers have done their work. It is what you want for text, for shortcuts you describe to users (“press S to save”), and for anything where the letter matters. event.code answers “which physical key was that?”: a name for the key’s position, such as KeyQ or Digit1 or ShiftLeft, that MDN describes as a value that “isn’t altered by keyboard layout or the state of the modifier keys”. It is what you want for games and anything that treats the keyboard as a set of buttons: WASD stays in the same place under the left hand on an AZERTY board even though the letters there are ZQSD, and MDN’s own warning is the flip side, that you cannot use code to tell the user which letter is on the key. keyCode (and its alias which) is the legacy number from before either existed; it is deprecated, varies by browser for punctuation, and cannot distinguish left from right modifiers or a numpad digit from a top-row one without the separate location property (0 standard, 1 left, 2 right, 3 numpad). Modern code reads key or code and ignores keyCode unless it must support very old browsers.

    Why keyCode is deprecated

    MDN’s description of keyCode is “a system and implementation dependent numerical code identifying the unmodified value of the pressed key”, with the instruction to avoid it and use code or key instead. The problems it names are the ones you will meet in practice. The numbers for letters and digits are consistent (65 to 90 and 48 to 57), but punctuation was never standardised: Firefox historically reported 173 for Minus, 61 for Equal and 59 for Semicolon where other browsers reported 189, 187 and 186. The value describes the “unmodified” key, so Shift-1 and 1 share a keyCode while key tells them apart. Left and right modifiers share a number. Non-US layouts produce numbers that do not match any table, because the number followed the platform’s virtual-key code for whatever character the layout put there. And during input-method composition many browsers report 229 for every key. None of this is fixable inside keyCode, so the UI Events specification replaced it with two well-defined strings. If you maintain old code, this page shows you the keyCode your browser emits today next to the code to migrate to; the table below lists the common pairs.

    Full key code table

    Values of event.code with the event.key you get on a US layout (unshifted / shifted) and the legacy keyCode as documented by MDN. The key column changes with layout; the code column does not. Browser notes are in the last column.

    event.codeevent.key (US layout, unshifted / shifted)keyCode (legacy)Notes
    KeyAa / A65
    KeyBb / B66
    KeyCc / C67
    KeyDd / D68
    KeyEe / E69
    KeyFf / F70
    KeyGg / G71
    KeyHh / H72
    KeyIi / I73
    KeyJj / J74
    KeyKk / K75
    KeyLl / L76
    KeyMm / M77
    KeyNn / N78
    KeyOo / O79
    KeyPp / P80
    KeyQq / Q81
    KeyRr / R82
    KeySs / S83
    KeyTt / T84
    KeyUu / U85
    KeyVv / V86
    KeyWw / W87
    KeyXx / X88
    KeyYy / Y89
    KeyZz / Z90
    Digit00 / )48
    Digit11 / !49
    Digit22 / @50
    Digit33 / #51
    Digit44 / $52
    Digit55 / %53
    Digit66 / ^54
    Digit77 / &55
    Digit88 / *56
    Digit99 / (57
    Space" "32
    EnterEnter13
    TabTab9
    BackspaceBackspace8
    EscapeEscape27
    CapsLockCapsLock20
    ShiftLeftShift16
    ShiftRightShift16
    ControlLeftControl17
    ControlRightControl17
    AltLeftAlt18
    AltRightAlt (AltGraph on some layouts)18
    MetaLeftMeta91Mac keyboards: Command reports as Meta
    MetaRightMeta93MetaRight: 92 on Windows browsers historically, 93 in Firefox; MDN lists both
    ContextMenuContextMenu93
    ArrowLeftArrowLeft37
    ArrowUpArrowUp38
    ArrowRightArrowRight39
    ArrowDownArrowDown40
    HomeHome36
    EndEnd35
    PageUpPageUp33
    PageDownPageDown34
    InsertInsert45
    DeleteDelete46
    PausePause19
    ScrollLockScrollLock145
    NumLockNumLock144
    PrintScreenPrintScreen44 (keyup only in most browsers)
    F1F1112
    F2F2113
    F3F3114
    F4F4115
    F5F5116
    F6F6117
    F7F7118
    F8F8119
    F9F9120
    F10F10121
    F11F11122
    F12F12123
    Backquote` / ~192
    Minus- / _189Firefox historically 173
    Equal= / +187Firefox historically 61
    BracketLeft[ / {219
    BracketRight] / }221
    Backslash\\ / |220
    Semicolon; / :186Firefox historically 59
    Quote' / "222
    Comma, / <188
    Period. / >190
    Slash/ / ?191
    IntlBackslash\\ / | (ISO key left of Z)226layout-dependent
    IntlRo\\ / _ (JIS)193layout-dependent
    IntlYen¥ / |255layout-dependent
    Numpad0096Num Lock off: navigation key names
    Numpad1197Num Lock off: navigation key names
    Numpad2298Num Lock off: navigation key names
    Numpad3399Num Lock off: navigation key names
    Numpad44100Num Lock off: navigation key names
    Numpad55101Num Lock off: navigation key names
    Numpad66102Num Lock off: navigation key names
    Numpad77103Num Lock off: navigation key names
    Numpad88104Num Lock off: navigation key names
    Numpad99105Num Lock off: navigation key names
    NumpadMultiply*106
    NumpadAdd+107
    NumpadSubtract-109
    NumpadDecimal.110
    NumpadDivide/111
    NumpadEnterEnter13
    AudioVolumeMuteAudioVolumeMute173media keys: browser and OS dependent, often not delivered
    AudioVolumeDownAudioVolumeDown174media keys: browser and OS dependent, often not delivered
    AudioVolumeUpAudioVolumeUp175media keys: browser and OS dependent, often not delivered
    MediaPlayPauseMediaPlayPause179media keys: browser and OS dependent, often not delivered
    MediaTrackNextMediaTrackNext176media keys: browser and OS dependent, often not delivered
    MediaTrackPreviousMediaTrackPrevious177media keys: browser and OS dependent, often not delivered
    BrowserBackBrowserBack166media keys: browser and OS dependent, often not delivered
    BrowserForwardBrowserForward167media keys: browser and OS dependent, often not delivered

    Handling keyboard layouts and IME

    Two situations break naive key handling. Layouts. On a German board the key at the QWERTY Y position types Z, on French AZERTY the key at Q types A, and on Dvorak nearly everything moves. If your handler uses code, physical positions stay put, which is right for game controls and wrong for letter shortcuts: a “press S” hint would point German users at the correct key but French users at the wrong one. If it uses key, letters follow the user’s expectations but positional clusters (WASD) scatter. The usual answer is code for movement and key for commands, and the Keyboard API’s getLayoutMap(), where available, to label a physical code with the character it currently produces. ISO boards add a key that ANSI boards lack, IntlBackslash, next to the left Shift; the ANSI vs ISO guide shows where it is and what it reports. Input method editors. When a user types Japanese, Chinese or Korean, or composes accented characters with dead keys, the keyboard events do not correspond to the text being produced. Browsers report key as Process or Unidentified and keyCode as 229 during composition, and isComposing is true; the text arrives through composition events and input events instead. Handlers that act on keydown must check isComposing and leave those presses alone, and anything that depends on the typed text should listen to the input event rather than reconstruct it from keys. The Dead value of key marks a dead key press that produces nothing on its own.

    Copy-ready snippets

    The snippet in the frame is rewritten with each key you press; the default pattern is a keydown listener that checks code for the physical key and key for the character, with comments saying which is which, in plain JavaScript or as a React effect with cleanup. A few conventions worth copying along with it: check event.isComposing before acting on keydown; prefer code for anything positional and key for anything textual; use location or the Left/Right codes to tell modifiers apart; never store keyCode in new code; and call preventDefault only for keys you actually handle, so the browser’s shortcuts keep working for everything else. The input tests hub lists the user-facing keyboard tests built on the same events.

    Frequently asked questions

    What is the difference between event.key and event.code?

    key is the character or key name after the keyboard layout and modifiers have been applied: what the user typed. code is the physical key position, the same regardless of layout or Shift. MDN's example: the code KeyQ is the Q key on QWERTY, the ' key on Dvorak and the A key on AZERTY. Use key for text and shortcuts shown to users, code for game-style controls that depend on where a key sits.

    Is keyCode deprecated?

    Yes. MDN describes keyCode as deprecated and system- and implementation-dependent, and says to use code (physical key) or key (character) instead. keyCode and which still work in current browsers for old code, but values for punctuation differ between browsers and layouts, which is one reason they were replaced.

    Why is the keyCode for a punctuation key different in Firefox?

    Because keyCode was never standardised for those keys; each browser inherited different platform conventions. The table marks the historical Firefox values for Minus, Equal and Semicolon. event.code avoids the problem entirely: it is Minus, Equal and Semicolon on every browser.

    Why does event.code come back empty or Unidentified?

    Some virtual keyboards, remote-desktop sessions, accessibility tools and older browsers do not report a physical code. Mobile on-screen keyboards in particular often send key with an empty code, or a key of Unidentified with keyCode 229 while an input method composes text. Handle the missing case: fall back to key, and treat 229 as composition in progress.

    How do I detect the left or right Shift key?

    Use event.code (ShiftLeft / ShiftRight) or event.location (1 for left, 2 for right, 3 for numpad). event.key is Shift for both. The same applies to Control, Alt and Meta, and to the numpad digits versus the top-row digits, which share a key value but have different codes and locations.

    Last updated:

    Reviewed by: TestPane Editorial Team

    Tested on: Chromium 141 (automated, synthetic key events), Firefox 142 (automated, synthetic key events), WebKit 26 (automated, synthetic key events)