Advertisement
Guide
About the JavaScript Keycode & Key Event Tester
When a key is pressed, the browser fires a keydown event with several properties describing it. Which one to check depends on what you need — the character typed, the physical key, or compatibility with old code. This tester shows them all for any key you press, so you can write a keyboard shortcut or debug one without guessing.
event.key vs event.code vs keyCode
event.keyis the value of the key —"a","A","Enter". It follows the keyboard layout and Shift, and is the one to use for most shortcuts.event.codeis the physical key position, such as"KeyA", whatever the layout. Use it for games and WASD-style controls.event.keyCodeandevent.whichare numeric codes that are deprecated and inconsistent across layouts, but still appear in older code.
Common key values
Enter is "Enter" (keyCode 13), Escape is "Escape" (27), Space is " " (32), Tab is "Tab" (9), and the arrows are "ArrowLeft", "ArrowUp", "ArrowRight" and "ArrowDown" (37–40). Press any key above to check others.
How to use it
- 1Click on the page so it has keyboard focus.
- 2Press a key or key combination.
- 3Read its properties, or click one to copy it.
- 4Copy the generated handler to use that key in your code.
Frequently asked questions
What is the keyCode for Enter?
event.keyCode is 13 for Enter. In modern code check event.key === "Enter" instead.
Is keyCode deprecated?
Yes. keyCode and which are deprecated in favour of key and code. Browsers still support them for old code, but new code should not rely on them.
How do I detect Ctrl+S or Cmd+S?
Listen for keydown and check (event.ctrlKey || event.metaKey) && event.key === "s", then call event.preventDefault() to stop the browser’s save dialog.
Why does my phone show “Unidentified”?
On-screen keyboards on Android often send keydown with key "Unidentified" and keyCode 229 while composing text. Listen for input events instead when handling touch keyboards.
What is event.location?
It tells left and right modifier keys apart and flags the numeric keypad: 0 standard, 1 left, 2 right, 3 numpad.
