Skip to content

JavaScript Keycode Finder

Press a key to see event.key, event.code and keyCode. Runs in your browser.

Loading tool…

About this javascript keycode finder

This keycode finder shows the JavaScript values for any key you press: event.key, event.code, the old keyCode and which numbers, the location, and every modifier state. It is for web developers writing keyboard shortcuts, game controls or form handling who need the exact value to compare against.

Press a key and you also get a ready keydown snippet that matches it, written either with e.key or with e.code. A table of over 100 common keys covers the cases you cannot press, and an event log shows the keydown and keyup order with timing.

If you want to test a physical keyboard instead, with a full on-screen layout, rollover and chatter checks, use the keyboard tester. This page is the developer view.

Features

  • Every KeyboardEvent value

    key, code, keyCode, which, location (standard, left, right or numpad), repeat and isComposing, each with a copy button.

  • Modifier states

    ctrlKey, shiftKey, altKey and metaKey, plus CapsLock, NumLock and AltGraph read through getModifierState.

  • Copy-ready snippet

    A keydown listener with the exact condition for the press you made, such as e.ctrlKey && e.key === "k". Switch between matching by key or by code.

  • Shortcut label

    The press written as a shortcut, such as Ctrl+Shift+K, or with Cmd and Option on a Mac.

  • Event log with timing

    The last 30 keydown and keyup events with the milliseconds between them, so you can see auto-repeat and the order modifiers arrive in.

  • Key code table

    Searchable list of key, code and legacy keyCode for letters, digits, F1 to F12, arrows, the number pad and punctuation, with Firefox differences noted.

  • Shortcuts stay inside the box

    Inside the capture box, keys like Space, arrows and F5 are captured so the page does not scroll or reload. Tab still moves focus out. Some combinations, such as Ctrl+W, are reserved by the browser and cannot be captured by any page.

How to use the javascript keycode finder

  1. 1Click the capture box and press any key or shortcut.
  2. 2Read event.key, event.code, keyCode, location and the modifier states.
  3. 3Copy a value or the ready keydown snippet, matched by key or by code.

When to use it

  • Writing a keyboard shortcut

    Press Ctrl+K, copy the generated condition, and paste it into your handler. On a Mac, press Cmd+K and you get e.metaKey instead.

  • Game controls that work on any layout

    Press W on an AZERTY keyboard: e.key is "z" but e.code is "KeyW". Match by code and your WASD controls sit in the same place for everyone.

  • Replacing old keyCode checks

    Legacy code full of keyCode === 13? Press Enter to confirm the modern value is "Enter" and rewrite the check.

  • Debugging a key that does nothing

    Check whether the key reaches the page at all, whether a modifier is stuck, or whether an IME is sending keyCode 229.

event.key vs event.code: which should I use?

event.key is the value the key produces: "a", "A" with Shift, "Enter", "ArrowUp", or "é" on a French keyboard. It follows the user's keyboard layout and modifiers. event.code names the physical key, using the US layout as the reference: the key right of Tab is always "KeyQ", even when it types an A on AZERTY.

Use key for text and for shortcuts tied to a letter (Ctrl+S means save on every layout). Use code for controls tied to a position, like WASD movement or a piano on the home row. Both are defined in the W3C UI Events specification.

Why is keyCode deprecated?

keyCode and which were never properly standardised. Browsers agreed on letters, digits and common keys, but punctuation differs: the semicolon key is 186 in Chrome and 59 in Firefox, and minus is 189 against 173. Values also change with the keyboard layout, and on Android virtual keyboards most keys report 229.

MDN and the UI Events specification mark both as deprecated. Browsers still support them so old sites keep working, which is why this tool still shows them. For new code, compare event.key or event.code instead.

  • Enter: key "Enter", code "Enter" (numpad: "NumpadEnter"), keyCode 13
  • Escape: key "Escape", code "Escape", keyCode 27
  • Space: key " " (a single space), code "Space", keyCode 32
  • Arrow keys: key and code "ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown", keyCode 37 to 40
  • Tab: key and code "Tab", keyCode 9
  • Backspace: key and code "Backspace", keyCode 8

What does event.location mean?

location tells apart keys that exist more than once. 0 is a normal key, 1 is the left version and 2 the right version of a modifier such as Shift, Ctrl, Alt or Meta, and 3 is the number pad. code carries the same information in its name ("ShiftLeft", "Numpad5"), so most code uses that instead.

Why do I get keyCode 229 or "Unidentified"?

An input method editor (IME) is handling the key. That happens with Chinese, Japanese and Korean input, and with most on-screen keyboards on Android. The key event fires, but the browser does not yet know which character will come out, so it reports 229 and key "Unidentified" or "Process".

For text, listen to the input or beforeinput event and read its data property. Check event.isComposing in keydown handlers so you do not act on keys that are still part of a composition.

Why use Mavros

 MavrosTypical upload sites
Values shownkey, code, keyCode, which, location, repeat, isComposingkeyCode and key
Modifier statesCtrl, Shift, Alt, Meta, CapsLock, NumLock, AltGraphCtrl, Shift, Alt
Code snippetkeydown listener matched by key or codeNone
Event logkeydown and keyup with timingLast key only
Mobile and IME noteExplains 229 and gives a text box to testNot covered
AdsNoneBanner ads around the box

Tips

  • Use keydown, not keypress. keypress is deprecated and never fires for keys like Escape, arrows or Backspace.
  • On macOS, other keys do not send keyup while Cmd is held, so clear any "keys held" state when Meta is released.
  • Call preventDefault only for the exact combination you handle, so browser shortcuts like Ctrl+F still work for your users.
  • Comparing e.key with a letter? Lowercase it first, or a press with Caps Lock on will not match.
  • Matching keys with a regular expression? Try the pattern in the regex tester against real key names first.
  • Building a shortcut config file? Keep the codes in JSON and check it with the JSON formatter, and look up other developer tools for the rest of the job.

Questions

What is the keyCode for the Space bar?

32. Its event.key is a single space character " ", not the word Space, and its event.code is "Space". Many bugs come from comparing e.key with "Space".

What is the key code for Escape?

keyCode 27. event.key is "Escape" and event.code is "Escape". Old versions of Internet Explorer and Edge reported key as "Esc", so very old code sometimes checks for both.

How do I detect Ctrl+S in JavaScript?

In a keydown listener, check (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s", then call e.preventDefault() to stop the browser's save dialog. Including metaKey makes it work as Cmd+S on a Mac.

Is event.which the same as keyCode?

For keydown and keyup, yes: browsers set which to the same number. Both are deprecated. which also appears on mouse events, where it means the button, which is a separate thing.

Why does event.key change with Shift but event.code does not?

Because key is the character produced and code is the physical key. Shift+1 gives key "!" on a US layout, while code stays "Digit1".

Can a web page detect the Fn key?

No. Fn is handled inside the keyboard and never sent to the computer. You only see the result, such as a media key or F5, if the system passes it to the browser.

Does this work on a phone?

Partly. Use the text box at the bottom of the tool to open the on-screen keyboard. Many mobile keyboards report keyCode 229 and key "Unidentified" for letters, which is how those browsers behave, not a fault in the tool.