event.key vs event.code vs keyCode
Every key press in the browser fires a KeyboardEvent with several properties. event.key is the value the key produces, such as "a", "A", "Enter" or "ArrowUp", and it follows the user's keyboard layout and Shift state. event.code describes the physical key, such as "KeyA" or "Digit1", so it stays the same on QWERTY, AZERTY or Dvorak keyboards. keyCode and which are old numeric codes that are deprecated and inconsistent across browsers and layouts. Modern code should use event.key for text and shortcuts, and event.code when the position matters, like WASD controls in games.
Features
- • Shows event.key, event.code, keyCode and event.location for any key
- • Modifier state for Ctrl, Shift, Alt and Meta, plus key repeat
- • Ready-to-copy JavaScript if statement for the pressed key
- • History of the last keys pressed
- • Prevents scrolling for Space and arrows while you test
Private by design
Key events are read only on this page, in your browser. Nothing you press is recorded or sent anywhere.