Tools / JavaScript Keycode Viewer

JavaScript Keycode Viewer.

Press any key to see event.key, event.code, keyCode, location and modifiers, with a ready keydown handler.

Runs in your browser
⌨ Click here and press any key
event properties
keydown handler

            
Recent keys
keycodekeyCodelocationmodifiers

About JavaScript Keycode Viewer

The JavaScript Keycode Viewer shows exactly what the browser reports when you press a key. Focus the page and press anything, a letter, an arrow, a function key or a shortcut such as Cmd+K, and you see event.key (the character or key name the user meant, like "k", "Enter" or "ArrowUp"), event.code (the physical key position, like KeyK or Numpad7), the deprecated keyCode and which numbers that old code still checks, event.location (left, right or numpad), the modifier keys held and whether the event is an auto-repeat. A history of recent presses makes it easy to compare keys, for example the left and right Shift or the two Enter keys. For each key the tool writes a keydown handler with the right condition, such as event.key === 'k' && event.metaKey for a command palette shortcut. Use event.key for shortcuts tied to a letter and event.code for game controls that should stay in the same place on AZERTY or Dvorak keyboards. Common mistakes are comparing keyCode, which differs between layouts and browsers, listening to keypress, which is deprecated and misses non-character keys, and forgetting that Shift changes event.key from "a" to "A". Some combinations are reserved by the operating system and never reach the page. Nothing is recorded or sent: the viewer runs in your browser.

How to Use

  1. Click the capture area and press any key or shortcut.
  2. Read event.key, event.code, keyCode, location and modifiers.
  3. Copy the generated keydown handler.

Frequently Asked Questions

Should I use event.key or event.code?

event.key for shortcuts that refer to a character (Ctrl+S) and event.code when the physical position matters (WASD in games), because code ignores the keyboard layout.

Is keyCode still safe to use?

It still works but is deprecated and inconsistent across layouts. New code should use key or code.

Why does a shortcut not show up?

The operating system or browser handles some combinations (Cmd+Tab, Ctrl+Alt+Delete, Cmd+W) before the page receives them.

Are my keystrokes recorded?

No. They are only shown on this page and are never stored or sent anywhere.

Related Tools