JavaScript Keycode Explorer

Press any key to instantly see event.key, event.code, keyCode, charCode, location, repeat, and modifier states. Ready-to-copy JS snippet. Runs in your browser, no setup.

  • Runs in your browser
  • Tool input is not uploaded to ZeroTool servers
  • Free · No Sign-Up
Copy copies the complete JS snippet shown in the result area. Clear resets the event fields, count, history, modifier indicators and snippet. Ctrl/⌘+L clears when focus is elsewhere in this tool; while the pad has focus it captures that shortcut as a key.
Capture pad Click the pad, then press a key; it also takes focus on first load. Tab, Space, Backspace, arrows and F1–F12 prevent their default actions here. Some browser or system shortcuts never reach the page.
Click here, then press any key
⌨
0 keys captured

Event properties

Read the raw key, physical code, legacy keyCode/which/charCode, location, repeat and isComposing values from the latest keydown. The legacy numeric properties are deprecated.
event.key —
event.code —
keyCode (deprecated) —
which (deprecated) —
charCode (deprecated) —
location —
repeat —
isComposing —

Modifier keys

Shift, Ctrl, Alt and Meta indicators reflect the modifiers on the latest captured keydown. They update on the next captured key.
Shift Ctrl Alt Meta

Ready-to-copy JS snippet

The snippet matches event.key and the captured modifiers. It changes immediately with each captured key; it does not use event.code.

Recent keys

Recent keys keeps the latest eight captures, newest first. The pad count includes every capture since Clear.
Read the full guide Why event.keyCode Lies to You: A Modern Guide to JavaScript Keyboard Events
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.

event.key vs event.code vs keyCode

Most front-end keyboard bugs come from mixing these three. Use this table as a reference:

PropertyLayout-awareRecommendedExample for A on QWERTY
event.keyYes (reflects active layout)Yes — semantic checks"a" or "A" with Shift
event.codeNo (physical position)Yes — game / shortcut bindings"KeyA"
keyCodeNoNo — deprecated65
whichNoNo — deprecated65
charCodeNoNo — deprecated, 0 on keydown0

Worked examples

Each block below is what the pad shows for the given key: a few rows from Event properties, then the Ready-to-copy JS snippet.

Ctrl+Shift+K for a command palette

With Shift held, the key value of a letter is the upper-case letter. The UI Events KeyboardEvent key Values spec gives the same example: the key labelled Q is "q", or "Q" with Shift. A handler that compares with 'k' never fires.

event.key   "K"
event.code  "KeyK"
keyCode     75
document.addEventListener('keydown', (e) => {
  if (e.key === 'K' && e.ctrlKey && e.shiftKey) {
    // your handler
  }
});

The letter a on a French AZERTY keyboard

The key labelled a on AZERTY sits where q is on a US keyboard, so its code is "KeyQ" (from the code values spec). The snippet compares key, so it matches the letter the user typed.

event.key   "a"
event.code  "KeyQ"
document.addEventListener('keydown', (e) => {
  if (e.key === 'a') {
    // your handler
  }
});

The space bar

Recent keys and the big label on the pad show Space, but the key value is a single space character, and the code is "Space". Copy the snippet rather than typing 'Space' by hand.

event.key   " "
event.code  "Space"
document.addEventListener('keydown', (e) => {
  if (e.key === ' ') {
    // your handler
  }
});

Common Use Cases

  • Debugging keyboard handlers — paste the exact event.key into your conditionals to fix typos.
  • Building game controls — prefer event.code so WASD works on AZERTY layouts.
  • Wiring command palettes — combine event.key with e.ctrlKey / e.metaKey checks.
  • Auditing legacy code — read keyCode / which to map old handlers to event.key.
  • Identifying composing state — e.isComposing = true means an IME is active, so single-key handlers should return early.

Preventing Default Behavior

The capture pad calls preventDefault() only on Tab, Space, Backspace, Arrows, and F1-F12 — keys the browser would otherwise consume for navigation or page actions. System shortcuts like Ctrl+W / Cmd+Q are not intercepted; they continue to do their default thing.

Keyboard Layouts and Input Methods

event.code names the physical key after its position on a US keyboard. The UI Events KeyboardEvent code Values spec lists "KeyQ" as the key labelled q on a US keyboard and a on a French AZERTY keyboard. Use code for shortcuts that depend on where a key is (WASD movement) and key for shortcuts that depend on what the key types (Ctrl+Z for undo).

Japanese and Korean keyboards add keys that a US keyboard does not have: "IntlYen", "IntlRo", "NonConvert", "Convert" and "KanaMode" on a Japanese 106/109 keyboard, and "Lang1" (한/영) and "Lang2" (한자) on a Korean keyboard. On a Mac Japanese keyboard, the same two codes are the かな and 英数 keys. Press them on the pad to see the values your browser reports.

While an input method is composing text, isComposing is true, and the non-normative legacy section of UI Events says keyCode is 229 on keydown. Check isComposing before you act on Enter, or the key that confirms a Japanese or Chinese conversion will also submit your form. The snippet from this tool does not add that check; add it yourself:

input.addEventListener('keydown', (e) => {
  if (e.isComposing || e.keyCode === 229) return;
  if (e.key === 'Enter') {
    // submit
  }
});

Limits

  • On phones and tablets, on-screen keyboards usually send an input event with the typed text instead of a full keydown. The fallback field below the pad shows that text as key and leaves code, keyCode, which and charCode empty, because the input event does not say which key was used. While an input method is composing, the field ignores the intermediate input events and reads the committed text at compositionend. This was checked with simulated composition events (Japanese, Korean, Chinese pinyin) and with Chromium's input-method emulation on a desktop, not on an Android device.
  • The browser and operating system keep some shortcuts, such as Ctrl+W or Cmd+Q, so the page never sees them.
  • The pad is a focusable area, not a text field. Whether an input method composes text there depends on the operating system and the input method, so the pad may not show keyCode 229.
  • The snippet compares event.key and the held modifiers only. It does not use event.code and does not check isComposing.
  • Only keydown is captured; keyup and keypress are not shown. Recent keys keeps the last eight captures.

FAQ

What's the difference between event.key, event.code, and keyCode?

event.key is the character or named key value after the keyboard layout and Shift are applied. event.code names the physical key by its position on a US keyboard (KeyA, Digit1, ArrowUp) and does not change with the layout: the key labelled a on a French AZERTY keyboard reports key "a" and code "KeyQ". keyCode is the legacy number (65 for A); browsers still send it for old code.

Why are keyCode, which, and charCode deprecated?

The UI Events specification calls them obsolete, does not define their values, and says authors should use the key attribute instead of charCode and keyCode. Their values differ between browsers, operating systems and keyboard layouts. MDN marks them as deprecated. Browsers still send them for compatibility, and this tool shows the raw values so you can check old handlers.

How do I check for Shift / Ctrl / Alt / Meta modifier keys?

Read e.shiftKey, e.ctrlKey, e.altKey and e.metaKey on the KeyboardEvent; each is a boolean. e.metaKey is the Windows key on Windows and the Command key on a Mac. The generated snippet adds a clause for each modifier that was held. With Shift held, event.key for a letter is the upper-case letter, so Ctrl+Shift+K gives key "K", not "k".

Why does keyCode show 229, and what is isComposing?

While an input method (for Japanese, Chinese or Korean, for example) is composing text, isComposing is true. The non-normative legacy section of UI Events says keyCode is 229 on keydown when an input method is processing the key. A handler for Enter should return early in that case, or the Enter that confirms the text will also submit the form. The capture pad is a focusable area, not a text field, so whether an input method composes there depends on your system; test composition in your own input field. The touch fallback field waits for compositionend and reads the committed text then (checked with simulated composition events and Chromium's input-method emulation on a desktop, not on an Android device).

Does this work on mobile?

Partly. Many on-screen keyboards do not send a keydown for each character; you get an input event with the typed text. On touch devices the tool shows a fallback field below the pad: it shows the typed text as key and leaves code, keyCode, which and charCode empty. While an input method is composing (Japanese kana-kanji conversion, a Korean syllable, Chinese pinyin), the field leaves the text alone and shows the committed text, such as 東京, when composition ends. Some on-screen keyboards also compose Latin text word by word; then a whole word, such as hello, appears at once. This handling was checked with simulated composition events and Chromium's input-method emulation on a desktop, not on an Android device. For full keydown details, use a desktop browser with a physical keyboard.

Is any keypress data sent to a server?

No key values are sent. Events are read in your browser and nothing is saved. The page loads Google Analytics, which records the tool name and an action: keydown once, for the first key after the page loads or after Clear; copy_snippet after a successful copy; and mobile_input once, for the first text entered in the touch fallback field after the page loads or after Clear. It does not record which key you pressed.