About Keycode Info
Handling keyboard events in a web page means knowing each key's key, code, and the deprecated keyCode, which is hard to recall from memory. This tool listens to your real key presses locally in your browser and shows the live event.key, event.code, keyCode, location, and Ctrl/Shift/Alt/Meta modifier states, so you can build shortcuts and debug input logic. Every keystroke is captured and handled only on this page and is never logged or sent anywhere. The usual problem with keyboard interactions is not that a key fails to respond but that it fails on someone else's keyboard: input methods in other languages, different keyboard layouts, and browser and operating system differences all make one piece of logic behave inconsistently. A lookup tool turns the abstraction into an observable fact, showing what the browser actually reports when a key is pressed. Modern events carry three pieces of information: the key value, meaning the character produced, the code, meaning the physical position, and a legacy numeric identifier that is now deprecated. Telling "which key was pressed" from "what character was entered" requires understanding the difference between the first two: holding shift changes the character to uppercase while the physical position stays the same. A Chinese input method reports a special identifier while confirming a candidate before the real submit fires. Practical notes: For shortcuts, do not test letters by character value, since changing keyboard layout makes the same physical key produce different characters, so testing position is more stable. For input validation the reverse holds, and the character is what matters. Skip handling explicitly while an input method is composing, or selecting a candidate is misread as a submit, which shows up in forms as "the form submits early while typing Chinese". With modifier combinations, test the combination before the single key, so a single-key rule does not swallow the combination. Limits: The same function key may report different values across systems, so a cross-platform product should keep the main flow working and degrade gracefully on edge keys. The legacy numeric identifier is deprecated yet still relied on by older code, so confirm the target browser range before assuming it is absent. One more easily missed point: keyboard events injected by assistive tools and automated tests often carry only some fields, so judging by a single field lets tests pass while real users fail, which makes manual verification on a real device necessary. Data and privacy: keyboard events contain no personal information themselves, but logging a key sequence can indirectly expose what was typed, so do not collect key data on a production page over time. This tool only displays information about the current key, records no sequence and uploads nothing, and works offline. The most common misuse is testing shortcuts by character: changing keyboard layout makes the same physical key produce a different character and the shortcut stops working, while it behaves perfectly on the developer own keyboard, so the bug looks intermittent. Another is ignoring the input method composing state, so committing a candidate submits the form. Handle composing first, then match on key position.
How It Works Internally
Modern key events carry three pieces of information: the key value, meaning which character the press produced, the code, meaning the physical position, and a legacy numeric identifier that is deprecated. Telling "which key" from "what character" rests on the first two — shift makes the character uppercase while the position is unchanged; and an input method emits an event with a composing flag while confirming a candidate before the real submit fires.
Press the A key top-left (English layout, no modifiers)key = "a" | code = "KeyA" (physical position) | on another layout key changes while code does notMeasured on This Page
| 4/4 keys correct | Enter→key=Enter/code=Enter, Tab→Tab, a→KeyA, ArrowUp→ArrowUp — both the character and the physical code match |
|---|---|
| Real event path | Injected through CDP Input.dispatchKeyEvent, so the browser's native event chain runs rather than a synthetic JS event |
| Modifier detection | The page reads shiftKey/ctrlKey/altKey/metaKey, which only matters when real keys are pressed |
| History | Recent entries are kept (key + code + time) so different keyboard layouts can be compared |
The key-versus-code distinction is the point of this page (all 4 measured keys match): key is the character (layout dependent — with a Chinese IME the same physical key can yield a different value) while code is the physical position (KeyA on a US layout). Game shortcuts should listen to code; text input and modifier logic should read key. keyCode is deprecated in the specification and new code should not depend on it. One more trap: with an IME active, keydown may not fire at all or key becomes 'Process', so switch to English input before debugging shortcuts.
How to Use
- Open "Keycode Info"
- Press any key while the page is focused
- Read the key, code, keyCode and location values
- Hold Shift, Ctrl or Alt to confirm the modifier state
- Click "Copy" to save the values
Use Cases
- Build shortcuts — Measure the key and code a combo produces and write the keydown listener without guessing.
- Tell keys apart — Use code to distinguish left vs right Shift, or main-row vs numpad digits that share a name.
- Legacy mapping — Find the modern key/code for an old keyCode value to migrate smoothly to the new API.
- Layout checks — Verify the key produced by one physical key under different keyboard layouts.
- Game controls — Confirm the code values when mapping WASD for a web game so input methods do not interfere.
- Keyboard shortcut testing — Verify the exact key codes fired by a keyboard shortcut combination to debug event handler conflicts.
- Cross-browser comparison — Compare key codes across different browsers to ensure your keyboard event handling works universally.
FAQ
What is the difference between event.key and event.code?
key is the character a press produces and changes with layout and Shift (a vs A); code is the physical key position and does not (KeyA stays KeyA). Bind shortcuts to code, not key.
Why is keyCode discouraged now?
keyCode is deprecated by the standard, its values differ across browsers and layouts, and it survives only for legacy compatibility. New projects should use key or code.
What is the location field for?
location marks the position of same-named keys — left Ctrl is 1, right Ctrl is 2, numpad keys are 3 — letting you tell the main keyboard and numpad apart for the same symbol.
Why can't some combinations be captured?
Some combos are intercepted first by the OS or browser (certain F keys, system shortcuts) and never bubble to the page; this is a platform limit a web page cannot override.
Are key values reliable during IME input?
During composition for languages like Chinese, isComposing is true and key may be Process; handle input after compositionend to avoid misreading keys.
A keyboard shortcut works on my keyboard but not on a colleague is. Why?
Most likely the logic tests the character. Changing keyboard layout makes the same physical key produce a different character, which breaks a shortcut that matches letters by value. Test the physical position instead, which is layout-independent; for input validation the reverse applies, since content matters rather than key position. Mixing up the two directions is the usual cause.
The form submits early while typing Chinese. How do I fix it?
An input method emits a key event while confirming a candidate, and only then does the real submit occur. If the key handler does not check the composing state, that confirmation is treated as an Enter submit. Skip key handling while composing, or listen for the form submit event instead of keys, which neither depends on input method behaviour nor blocks a genuine Enter submit.
keyCode is deprecated — why look it up at all?
Because plenty of legacy code and internal systems still listen for keyCode values (13 = Enter). New code should use event.key ("Enter") or event.code (the physical key). The table exists to decode legacy handlers quickly, not to encourage keyCode in new projects.