FormatterHQ

JavaScript Key Code Finder

Press a key to see exactly what a keydown event reports: event.key, event.code, the legacy keyCode, location, modifiers and repeat, plus a ready-to-paste handler.

Loading tool…
Ready.

How to use the JavaScript Key Code Finder

  1. Click the large key pad so it shows Listening….
  2. Press any key or shortcut, such as Enter or Ctrl + S; press Tab when you want to leave the pad.
  3. Read event.key, event.code, keyCode, location, modifiers and repeat on the cards, and click any card to copy its value.
  4. Copy the generated Handler snippet, or open the Key code table and filter it by name or number.

Find Any JavaScript Keycode by Pressing the Key

Writing a keyboard shortcut means knowing exactly what the browser reports for a key, and that is easy to get wrong. This JavaScript keycode finder shows the live KeyboardEvent values for whatever you press: event.key, event.code, the legacy keyCode, location, the active modifiers and whether the event is an auto-repeat. Your own browser, keyboard layout and operating system produce the values, so what you see is what your handler will receive.

event.key vs event.code vs keyCode

  • event.key is the character or named key produced, respecting layout and Shift: "a", "A", "Enter", "ArrowUp". Use it when the meaning matters, such as "save on S".
  • event.code names the physical key position, ignoring layout: "KeyA", "Digit1", "NumpadEnter". Use it for games and WASD controls, where the position matters on AZERTY and QWERTY keyboards alike.
  • keyCode is a deprecated number (Enter is 13, A is 65). It is inconsistent across layouts and browsers, so only read it when you maintain old code.

event.location tells left from right modifiers and numpad keys: 0 is standard, 1 left, 2 right and 3 numpad. That is how you tell the two Shift keys apart.

Example: a Ctrl+S handler

Pressing Ctrl + S on a US layout generates this snippet:

document.addEventListener('keydown', (event) => {
  if (event.ctrlKey && event.key === "s") {
    event.preventDefault();
    // ...
  }
});

// Physical key (layout independent): event.code === "KeyS"

The preventDefault() call stops the browser's own Save dialog. On macOS users expect Cmd, which shows up as metaKey, so many apps check event.ctrlKey || event.metaKey.

Common pitfalls

  • Shift changes event.key. Shift + S reports "S", not "s", and Shift + 1 reports "!" on a US layout.
  • Some shortcuts never reach the page. Combinations reserved by the OS or browser, like closing a tab, are handled before JavaScript sees them.
  • IME input. While composing text in Chinese or Japanese, keydown can report "Process" (keyCode 229) and isComposing is true, so skip shortcuts then.
  • Held keys repeat. Check event.repeat if an action should fire once per press.

To test a pattern on shortcut strings, try the regex tester, and to see the Unicode code point behind a character such as "é", use the Unicode character inspector.

Privacy

Key presses are read only inside the key pad while it has focus, and nothing is logged or sent anywhere. Everything runs in your browser.

Frequently asked questions

Is event.keyCode deprecated?
Yes. keyCode and which are marked deprecated in the UI Events spec, although browsers still support them for compatibility. New code should use event.key for the character or event.code for the physical key.
What is the keyCode for Enter, Escape and Space?
Enter is 13, Escape is 27 and Space is 32. Their modern equivalents are event.key values "Enter", "Escape" and " " (a single space), with event.code values Enter, Escape and Space. The key code table on this page lists the rest.
Why does my keypress handler not fire for arrow keys?
The keypress event is deprecated and only fires for keys that produce a character, so arrows, Escape and function keys never trigger it. Listen for keydown instead, which fires for every key.
How do I detect the numpad Enter key?
Both Enter keys report event.key "Enter", but the numpad one has event.code "NumpadEnter" and event.location 3. Check event.code when you need to treat them differently.

Last updated September 26, 2026

Related tools