JS Keycode Inspector
Press any key on your keyboard to instantly capture JavaScript event codes, key properties, and active modifier structures.
â¨ī¸ Press Capture Area
| event.key | - |
| event.code | - |
| event.which | - |
| event.location | - |
đ Key event properties
Press a key to view properties...
đ History Log
- No keys pressed yet.
W3C KeyboardEvent Specifications & Legacy keyCodes vs Modern Event.key
Handling keyboard interactions across web applications is essential for building accessible user interfaces, keyboard navigation shortcuts, game controls, and modal dialog handlers. Historically, web developers relied on the legacy event.keyCode and event.which numeric properties. However, the W3C officially deprecated these properties in the DOM Level 3 Events specification due to inconsistent cross-platform mappings and international keyboard layout failures.
Modern web development relies on two distinct, complementary standard properties:
event.key(Logical Meaning): Represents the printable character or semantic name of the key pressed (e.g."Enter","Escape","a","A","ArrowDown"). This property accounts for keyboard modifiers (such as Shift and AltGraph) and international localization.event.code(Physical Key Position): Represents the physical key location on the hardware keyboard (e.g."KeyA","Digit1","Space","Enter"). The code remains unchanged regardless of whether the user is typing in QWERTY, AZERTY, Dvorak, or Cyrillic layouts.
Our JS Keycode Inspector captures live keyboard events, displaying exact values for event.key, event.code, event.keyCode, modifier states (ctrlKey, altKey, shiftKey, metaKey), and location indexes in real time.
Production JavaScript Event Listener Pattern
Below is the recommended accessible keyboard event listener pattern for modern web applications:
// Accessible keyboard interaction pattern
document.addEventListener('keydown', (event) => {
// Check for modifier keys
const isCmdOrCtrl = event.metaKey || event.ctrlKey;
// Use event.key for semantic actions
if (event.key === 'Escape') {
closeActiveModal();
}
// Keyboard shortcut: Cmd+K or Ctrl+K (Command Palette)
if (isCmdOrCtrl && event.key.toLowerCase() === 'k') {
event.preventDefault(); // Prevent browser search focus
openCommandPalette();
}
// Use event.code for physical gaming/directional controls
if (event.code === 'KeyW' || event.code === 'ArrowUp') {
movePlayerForward();
}
});
Understanding Key Locations: Standard, Left, Right & Numpad
The event.location attribute differentiates between duplicate keys found across keyboards:
- 0 (DOM_KEY_LOCATION_STANDARD): Standard keys that only appear once or have no left/right distinction.
- 1 (DOM_KEY_LOCATION_LEFT): The left-hand modifier key (e.g. Left Shift, Left Ctrl, Left Alt/Option).
- 2 (DOM_KEY_LOCATION_RIGHT): The right-hand modifier key (e.g. Right Shift, Right Ctrl, AltGraph).
- 3 (DOM_KEY_LOCATION_NUMPAD): Keys located on the dedicated numeric keypad (e.g. Numpad Enter, Numpad 5).
IME Composition & International Input Handling
When users type in languages requiring Input Method Editors (IME) like Japanese, Chinese, or Korean, typing involves multi-keystroke composition buffers. During composition, event.isComposing is set to true and event.keyCode reports 229. Modern event listeners must verify !event.isComposing before triggering submission shortcuts to prevent premature form execution.
Related Developer Tools
Chain JS Keycode Inspector with these complementary client-side utilities from our Developer Tools collection:
Generate CSS Flexbox and Grid layouts online. Interactively configure direction, alignment, gap, column, and row specifications with real-time visual previews.
Generate JSON Schema from raw JSON documents instantly. Parse, identify types recursively, build property requirements, and export Draft-07, Draft-04, or Draft 2020-12 schemas.
Find the exact Git commands you need. Solve common scenarios like undoing commits, staging files, branch management, merging, and remote sync with interactive parameter builders.
Generate Keyed-Hash Message Authentication Codes (HMAC) locally in your browser. Supports SHA-256 and SHA-512 with custom secret keys. 100% private.
Frequently Asked Questions
keyCode values varied wildly between different operating systems, browsers, and international keyboards, resulting in fragile, layout-dependent code that frequently broke for global users.
keypress is officially deprecated and only fired for character keys. keydown fires immediately for every physical key press, including modifier keys, function keys, and navigation arrows.
Check both event.metaKey (Command on Mac, Windows key on PC) and event.ctrlKey (Control on all platforms) to support universal platform conventions.
No. Keystroke events are handled exclusively in memory within your active tab to display event properties and are never transmitted, logged, or saved.
Certain keys trigger native browser behavior (like shifting focus). Our inspector attaches listeners to the window object with preventDefault() options to ensure accurate capture.