About the JavaScript Keycode Finder tool
Keyboard shortcuts, games, accessible widgets and custom inputs all need to know exactly which key was pressed. JavaScript offers several overlapping properties for that: event.key, event.code, the deprecated keyCode and which, plus location and modifier flags. They behave differently across layouts, and documentation rarely shows what you will actually get.
Press any key on this page and the tool shows every property of the keydown event: the big keyCode number, event.key (the character or key name, which depends on keyboard layout), event.code (the physical key position, which does not), which, location (standard, left, right or numpad), whether the key is auto-repeating, and the state of Shift, Ctrl, Alt and Meta. A ready-to-paste JavaScript if statement is generated for the key you pressed, and recent keys are listed for comparison.
An option blocks default browser actions such as scrolling with the arrow keys while you test. A searchable reference table lists key, code and keyCode values for a US QWERTY keyboard. Everything runs locally and no keystrokes are recorded or sent anywhere.
How to use JavaScript Keycode Finder
- Click anywhere on the page so it has keyboard focus.
- Press the key or key combination you want to inspect.
- Read event.key, event.code, keyCode, which, location and the modifier badges.
- Copy the generated JavaScript snippet with the “Copy” button.
- Use the “Key code reference” table and its filter to look up other keys.
Features
Every key property
key, code, keyCode, which, location, repeat and all four modifier keys.
Layout insight
Compare key and code to see how layouts like AZERTY or Dvorak change the result.
Code snippet
Generates an if (event.key === …) check for the key you pressed.
Key history
Shows your last 12 key presses for quick comparison.
Reference table
Searchable list of key, code and keyCode values for common keys.
When to use it
- Add a keyboard shortcut such as Ctrl + K to open a search dialog.
- Build WASD or arrow-key controls for a browser game.
- Debug why a shortcut works on one keyboard layout but not another.
- Tell left and right Shift or numpad and main Enter keys apart.
- Make a custom dropdown or modal keyboard accessible.
Frequently asked questions
Should I use event.key or event.code?
Use event.key when you care about the character typed, such as “?” or “a”. Use event.code for physical positions, such as WASD game controls, which should stay in the same place on any layout.
Is keyCode deprecated?
Yes. keyCode and which are deprecated and inconsistent for some keys, but browsers still support them. Prefer key and code in new code.
Why does pressing a key do nothing?
The page must have focus, and key presses inside text fields are ignored so you can type in the filter. Some system shortcuts are captured by the operating system before the browser sees them.
Can I detect key combinations?
Yes. Check event.ctrlKey, shiftKey, altKey or metaKey together with event.key, for example event.ctrlKey && event.key === "s".
Does it work on phones?
On-screen keyboards often report generic values such as keyCode 229 or “Unidentified”. For accurate results use a physical keyboard.