event.key vs event.code: Writing Keyboard Shortcuts That Survive Layouts
November 19, 2026 · DevTools
Every keyboard shortcut bug that starts with "works on my machine" traces back to the same confusion: event.key is the character the active layout produces, while event.code is the physical key, stable across layouts. Press the key labeled Z on a QWERTY keyboard while a Dvorak or AZERTY layout is active, and the two properties disagree. The Keycode Info tool turns any keypress into the exact object JavaScript receives from a keydown listener, so you can see the difference instead of reasoning about it.
What one keypress shows you
Press Ctrl+C in the capture area and you get the full record:
- event.key —
"c": the character the layout produces, with Ctrl listed among the active modifiers. - event.code —
"KeyC": the physical key, layout-independent. - keyCode —
67: the deprecated legacy number, still shipped by every browser. - location — standard, left, right, or numpad: press each Shift key and
locationreports 1 or 2 whileevent.keystays"Shift"for both. - modifiers — the full Ctrl/Alt/Shift/Meta state.
A rolling history of the last 20 presses makes sequences easy to compare, and one click copies the current event as clean JSON in the exact field names you paste into code.
Which property should your shortcut use?
event.key when the shortcut means a character (Ctrl+F for find), event.code when it means a position (WASD movement, where the physical layout is the point), and event.key === "Escape"-style checks for control keys, where the two agree. The keyCode property is deprecated in the DOM standard — the tool displays it for legacy-code lookup alongside its modern replacements, never instead of them, so that old switch statement you inherited can be verified without being extended.
Beyond the single key
The static reference table below the capture area covers the common keys — letters, digits, control keys, arrows, function keys, modifier sides, and the numpad — as a standard US layout reports them. It's the lookup you need when writing tests that synthesize keyboard events, or when a bug report says "the shortcut fires the wrong action" and the reporter's layout is the variable. For character-level questions — which codepoint did that key produce — the Unicode Character Inspector takes over, and the Device Information page captures the surrounding environment for the bug report.
Keydown events are read locally and never leave the device — no network calls, no analytics on key content — so pressing real shortcut combinations, including ones with passwords adjacent, is safe by construction.