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.
Understanding Keyboard Events in JavaScript
Whenever a user interacts with a keyboard in the browser, the document fires specific user-interface events: keydown, keypress, and keyup. Developers capture these events to build custom keyboard navigation, build game loops, or set up accessibility shortcuts.
Managing keyboard inputs has historically been complex due to varying mappings between operating systems and physical hardware keyboard standards. Modern W3C standards advise migrating away from integer key identifiers (like which or keyCode) in favor of the string-based key and code properties.
Important event Properties Detailed
- event.key: Resolves to a DOMString containing the character represented by the keypress (e.g.
"?"or"Enter"). This handles language modifications. - event.code: Resolves to the physical position of the key on the QWERTY layout. Useful for game inputs (e.g. WASD keys remain positionally constant).
- event.location: Provides numeric values telling you if a key was pressed on the main block, numeric keypad, or left/right side modifications (like left shift vs right shift).
Frequently Asked Questions
event.key represents the character value generated by the keypress, taking keyboard layouts and modifiers into account (e.g. 'A' or 'a'). event.code represents the physical key pressed on the keyboard, independent of layout or modifier states (e.g. 'KeyA').
They are deprecated because they are inconsistent across browsers, platforms, and keyboard layouts. Modern applications should use event.key and event.code instead, which provide standard, reliable string representations of inputs.
The event.location property returns an unsigned long representing the physical location of the key on the keyboard: 0 for standard/default, 1 for left-side keys (like Left Shift), 2 for right-side keys (like Right Alt), and 3 for the numeric keypad.