JavaScript key code tester
Press any key to see its JavaScript key, code, keyCode, which, location, and modifier values as the browser reports them.
Key code tester workspace
How to use
4 short steps.
Press the key
The large readout shows event.key with event.code and the legacy keyCode number beside it. The cards below list every field.
Hold modifiers to see combinations
Hold Shift, Ctrl, Alt, or Meta with another key. The Modifiers card lists what was down, and key changes with Shift.
Compare left, right, and numpad keys
Press both Shift keys and a numpad digit. code and location tell them apart, while key and keyCode usually do not.
Copy the values
Click any value to copy it, or use Copy latest values for the whole event as JSON. The history below keeps the last ten events.
What the result means
Match what you see to one of these.
If you need the physical key, use code
If your code must react to a position regardless of the user's language, read event.code. KeyQ is the same key on a QWERTY, AZERTY, or Dvorak layout.
If you need the character, use key
If you want what the user typed, read event.key. It follows the active layout and Shift state, so the same key can produce q, Q, or a.
If a library still wants keyCode, treat the number as legacy
If you see keyCode or which, they are deprecated numbers that vary between browsers for some punctuation. Keep them for old code only and move to key and code.
Troubleshooting
If the test fails, try these in order.
Check that the page has focus
Click anywhere on the page away from links, then press the key again. Text fields and the address bar keep keys for themselves.
Watch for reserved shortcuts
F5, F11, Ctrl+W, and the Windows key are handled by the browser or system first. Press the key alone, then retest the combination in a native app if you need it.
Check Num Lock and the layout
A numpad digit reports End or an arrow when Num Lock is off, and key follows the system language. Change the setting and press the key again.
What this test can't tell you
Where a browser check stops.
- KeyboardEvent.code is not the hardware scan code, and keyCode and which are deprecated values that differ between browsers.
- Input method editors, dead keys, and remapping software change key while code stays position-based, so values here can differ from a native app.
FAQ
Common questions about this test.
How do I find the key code for a key?
Press it on this page. The large readout shows event.key, event.code, and the legacy keyCode number. For a full lookup table, the MDN KeyboardEvent reference lists every code.
What is the difference between key and code?
key is the character or action the key produces with the current layout and modifiers, such as a, A, or Enter. code is the physical position, such as KeyA, and does not change with language.
How can I show my keystrokes?
The history under the readout lists the last ten keydown and keyup events with key, code, and location. Press a sequence and read it back, or use Copy latest values to paste one event.
Why does Numpad 1 show End?
With Num Lock off the numpad sends navigation keys, so key becomes End while code stays Numpad1. Turn Num Lock on and the same key reports 1.
Should I still use keyCode?
No. keyCode and which are deprecated and inconsistent for punctuation across browsers. Use key for characters and code for positions. They stay visible here so you can debug older code.