Keycode info — Guide
Find the javascript keycode, code, location and modifiers of any pressed key.
What it is and when to use it
Press any key and see everything the browser tells you about the event: the legacy keyCode, the modern code (physical key), key (produced character), location and active modifiers. The fastest way to resolve "which value do I compare against" while wiring a keyboard shortcut or a game control scheme.
Press any key to see its keyCode, code, location and other details — useful when wiring up keyboard shortcuts.
How to use it
- Focus the page
- Press the key you want to inspect
- Read the details shown below
Things that trip people up
- keyCode is deprecated; prefer event.code or event.key in new code
Questions people ask
- Is keyCode deprecated?
- Yes — the spec marks it legacy and new code should use KeyboardEvent.code for physical keys or KeyboardEvent.key for characters. It is kept here because countless existing libraries and tutorials still compare against it.
- What is the difference between key and code?
- key is what the character produces and changes with layout and modifiers (Shift+1 gives "!"); code is the physical button regardless of layout (Digit1 in both cases). Shortcuts belong on code; text input belongs on key.
- Why do some keys differ between platforms?
- Physical layouts vary (ISO vs ANSI Enter, Mac Command vs Windows key) and location distinguishes left/right modifiers. Testing the real key on the target platform avoids surprises.
Next steps
- URL Encoder & Decoder
- Escape HTML entities
- URL parser
- Device information
- Basic auth generator
- Open graph meta generator
Spotted something wrong on this page? Tell us via Contact Us