Keyboard Key Code Finder
Press any key in the box below to see its KeyboardEvent key, code, location and modifiers, with a plain-English name for the key.
The box takes the Tab key, so Tab does not move focus out of it. Click anywhere else to leave the box.
How to use
- Click the box that says "Press any key here" so it has focus.
- Press a key. The result line and the five figures below update on every keydown.
- Hold Shift, Control, Alt or Meta while you press another key to see the Modifiers held figure change.
- Press the same key on the left and right side of the keyboard, or on the number pad, and compare the location figure.
- Click anywhere outside the box to hand focus back to the page. Tab is captured by the box, so it will not move focus out.
Worked example
Hold Shift and press the A key. The page reports key A (capital), code KeyA, location standard, modifiers Shift and the plain name "Letter A". Release Shift and press it again: key becomes a, while code stays KeyA. The first value follows the character produced, the second follows the physical key.
Now press 1 on the number pad. You get key 1, code Numpad1, location numpad and the name "Numpad 1". The same key value on the top row would give code Digit1 and location standard. The space bar reports key as a single space character and code Space.
How it works
The key is read in your browser, from the keydown event that the browser fires for the box. Nothing is sent or stored, and the page only reads keys pressed in the box. Keys pressed anywhere else are not read.
key is the character or key name after modifiers, so Shift turns a into A. code is the physical key, and it stays the same on every keyboard layout. location tells you whether a key is on the left or right side of the keyboard, or on the numpad.
keyCode and which are deprecated in the web standard, so this page does not use them. Source: MDN KeyboardEvent documentation.
The properties are defined by the W3C UI Events specification, with the code values listed in UI Events KeyboardEvent code Values. The MDN pages for KeyboardEvent.key and KeyboardEvent.code list the values in a readable form.
Which property to use in your code
| Goal | Use | Why |
|---|---|---|
| React to a typed character or a named key such as Enter | key | It follows the user's layout and modifiers. |
| Game controls such as WASD | code | The physical position stays the same on AZERTY or Dvorak layouts. |
| Tell left Shift from right Shift | code or location | key reports only "Shift" for both. |
| Detect Ctrl, Alt, Meta | the modifier flags | They are set on every key event while held. |
Common mistakes
- Using keyCode. It is deprecated, and its numbers differ by browser and layout. Use key or code.
- Using code for text input. On a French keyboard the physical KeyQ produces the letter A. Shortcuts based on code will confuse those users if they are meant to follow the printed letter.
- Ignoring input methods. While an IME composes text, key events can report "Process". Handle composition events separately for languages that need them.
- Forgetting auto-repeat. Holding a key sends repeated keydown events. Check the repeat property if an action should fire once.
- Assuming the browser sees every key. The operating system or browser may reserve shortcuts such as Alt+Tab or Ctrl+W, so the page never receives them.
Frequently asked questions
Why does a key show "Unidentified"?
Some keys, often media or special function keys, have no standard value, so the browser reports Unidentified for key.
Why are the codes the same on every keyboard layout?
The code names a physical position on a US-style layout, so KeyQ is always the key to the right of Tab, whatever is printed on it.
Does the page record what I type?
No. It reads keydown events in the box to fill the figures and keeps nothing.
Why does the Tab key not leave the box?
The box captures Tab so you can see its values. Click elsewhere to leave.
Are keypress and keyup supported?
The page reads keydown only. For most uses the values are the same on keyup.
Related tools
- Typing Speed Test to practise with a real keyboard.
- HTML Entity Encoder and Decoder for the characters that keys can produce.
- URL Parser and Query Builder for another everyday developer check.