Keyboard Event & Code Reference
KeyboardEvent.code describes a physical key position; KeyboardEvent.key describes the interpreted character or action. Compare both in the live keyboard event inspector when a key produces the wrong letter or a numpad behaves differently from the number row.
Common physical codes
These are typical hardware-keyboard events. Layout, OS, input method and browser can change what is exposed; an empty or unidentified code is possible.
| Key position | code | key | location |
|---|---|---|---|
| A position on US QWERTY | KeyA | a / A / a layout-dependent character | 0 |
| Number-row 1 | Digit1 | 1 or the shifted symbol | 0 |
| Keypad 1 | Numpad1 | 1 or End, depending on Num Lock | 3 |
| Main Enter | Enter | Enter | 0 |
| Keypad Enter | NumpadEnter | Enter | 3 |
| Left Shift | ShiftLeft | Shift | 1 |
| Right Shift | ShiftRight | Shift | 2 |
| Left Command / Windows | MetaLeft | Meta | 1 |
| Spacebar | Space | A space character (" ") | 0 |
| Up arrow | ArrowUp | ArrowUp | 0 |
Read an event without misdiagnosing the keyboard
- code
- Useful for identifying a position across layout changes. KeyQ does not guarantee the typed character is Q.
- key
- Reflects modifiers and the active input layout. A combining accent can report Dead; this is unrelated to a physically broken key.
- location
- 0 is standard, 1 is left, 2 is right, and 3 is the numeric keypad. Not every key has a left/right location.
- repeat
- True on an auto-repeating keydown. A held key repeating under OS settings is not automatically switch chatter.
- ctrlKey / altKey / shiftKey / metaKey
- Modifier state at the time of the event. AltGr interpretation varies by platform; use the resulting character as well.
- timeStamp
- The event creation timestamp, with browser precision restrictions. It is not the instant the physical switch closed.
Browser limitations
- Fn usually changes firmware behavior without a standalone browser event.
- System shortcuts, media controls and accessibility tools can intercept or transform input.
- Focus changes can hide a keyup. Held-key state is cleared when focus is lost.
- Virtual keyboards and IME composition may not emit the same key sequence as physical keyboards.
keyCodeis deprecated. It is displayed only for comparison with older software.
A reproducible diagnostic flow
- Press one key in the keyboard test and record its code and key locally.
- If the code arrives but the character is wrong, compare the input layout and remapping settings.
- If no event arrives, try another app and browser with the same connection before following the missing-key workflow.
- If only a combination fails, compare the ghosting test and rollover test.
References and methodology
Maintained by Keyboardtest. Updated . How we test and review guidance.