esc
No tool matches that yet.
  1. Home
  2. Hardware testers
  3. JavaScript key code finder

JavaScript key code finder

Press any key. You get every value a KeyboardEvent carries — key, code, keyCode, which, location and modifiers — for both keydown and keyup, plus a listener you can paste straight into your project.

event.keyCode — Press any key
ShiftCtrlAltMeta Caps LockNum LockAltGr

Click any value to copy it. On a phone? :

Last keydown

—

Last keyup

—

Code snippet

// Press a key (with any modifiers) to generate a listener for it.

Shortcut label: —

Keys pressed this session (0)

Keys pressed this session
keycodekeyCodewhichlocationpresses
Keys you press will be listed here, most recent first.

Key code reference

Common JavaScript key codes
Keyevent.keyevent.codekeyCodeNotes

Tab and Esc are never blocked, so the page stays usable with a keyboard.Values come straight from the browser's KeyboardEvent.

How to use the key code finder

Press any key while this page has focus. The large number is the legacy keyCode; the tiles beside it show every other property of the KeyboardEvent, and the pills below light up for held modifiers and for Caps Lock, Num Lock and AltGr. The Last keydown and Last keyup boxes let you compare the two events, which matters for keys such as Print Screen that only send a keyup on Windows. Click any value to copy it.

With Block browser shortcuts ticked, keys that would normally do something — F5 reloading, Space scrolling, / opening the site search — are captured instead, so you can read their codes. Tab and Esc are never blocked, so the page remains usable from the keyboard. A few combinations are reserved by the browser or operating system and cannot be intercepted by any web page, such as Ctrl+W, Ctrl+T and Alt+Tab.

key, code, keyCode and which: which should you use?

PropertyWhat it tells youUse it for
event.keyThe character or named key produced, after layout and modifiers: "a", "A", "Enter", "ArrowUp"Text-like shortcuts where the letter matters (Ctrl+F for Find)
event.codeThe physical key position, ignoring layout: "KeyA", "Digit1", "ShiftLeft"Games and WASD controls, where position matters more than the letter
event.keyCodeA legacy number such as 13 or 65, inconsistent between browsers for punctuationSupporting very old code only
event.whichLegacy alias of keyCode for key eventsNothing new

keyCode, which and charCode are deprecated in the UI Events specification. They still work in every browser and are not going away soon, but they describe letters as if every keyboard were a US one and disagree on punctuation — Firefox reports 59 for the semicolon where Chrome reports 186. New code should use key or code. The snippet builder lets you pick: by code matches the physical key, so a French AZERTY user presses the same position as a QWERTY user; by key matches the character, so the shortcut follows the letter printed on their keycap.

Generating a keydown listener

Press the exact combination you want, for example Ctrl+Shift+K, and the snippet panel writes a listener that checks the key and every modifier explicitly. Checking that unwanted modifiers are not held is deliberate: without it, a handler for Ctrl+K also fires on Ctrl+Shift+K and Ctrl+Alt+K, which on AltGr layouts are used to type characters. The JavaScript version ignores auto-repeat so holding the key triggers the action once; remove that line if you want repeats. The React version shows a component handler and a global useEffect listener with clean-up. Legacy produces an old-style keyCode check for maintenance work, and Event JSON dumps the full event for bug reports.

On a Mac, users expect Command rather than Control for most shortcuts. If you are building cross-platform shortcuts, check event.metaKey on macOS and event.ctrlKey elsewhere; the shortcut label under the snippet shows both notations.

Edge cases that catch developers out

  • IME and phone keyboards. While text is being composed (Chinese, Japanese, Korean input, and most Android keyboards), keydown reports keyCode 229 and key "Process" or "Unidentified". Check event.isComposing and read the input event instead. The field under the readout demonstrates this on a phone.
  • Dead keys. Accent keys on many European layouts report key "Dead" and only produce a character with the next key.
  • AltGr. On Windows, AltGr arrives as ControlLeft followed by AltRight, so a naive Ctrl check fires when someone types @ or €.
  • Numpad with Num Lock off. The same key reports "End" instead of "1", with a different keyCode, but its code is still Numpad1.
  • Caps Lock on macOS sends keydown when it turns on and keyup when it turns off.
  • Space. event.key is a literal space character, not the word Space.

To check that the physical keys themselves work, use the keyboard tester; for game controllers, the gamepad tester shows the equivalent button and axis indices from the Gamepad API.

Frequently asked questions

What is the keyCode for Enter?

Enter is keyCode 13, event.key "Enter" and event.code "Enter". The Enter key on the number pad also has keyCode 13 and key "Enter", but its code is "NumpadEnter" and its location is 3, which is how you tell the two apart if you need to.

Is keyCode deprecated? What should I use instead?

Yes. keyCode, which and charCode are deprecated, although every browser still supports them. Use event.key when you care about the character typed, such as Ctrl+F, and event.code when you care about the physical key position, such as WASD movement in a game. Both are supported in all current browsers.

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

event.key is what the key produces with the current layout and modifiers — "q" on a UK keyboard, "a" on a French AZERTY keyboard for the same key. event.code is the key's physical position and stays "KeyQ" on both. Use key for text-like shortcuts and code for positional controls.

Why do I get keyCode 229 on Android or when typing Chinese?

229 means an input method is composing text, so the browser cannot say which key was meant yet. Most Android on-screen keyboards behave this way for every key. Listen for the input or compositionend event and read the text from there, or check event.isComposing and ignore those keydown events.

Why doesn't a key show up at all?

Some keys never reach web pages. Fn is handled inside the keyboard, media keys and Print Screen are often taken by the operating system, and shortcuts such as Ctrl+W, Ctrl+T or Cmd+Q are reserved by the browser. If a normal key does nothing here, check it in the keyboard tester — the switch itself may be faulty.

Is anything I type recorded or sent anywhere?

No. Keys are read by JavaScript on this page and shown back to you. Nothing is uploaded or stored beyond your snippet style preference in local storage, and the session table disappears when you reset or close the page. Passwords are safe to test here, but there is no reason to type one.

Hardware testers