JavaScript Keycode Finder
Press any key to instantly see its keyCode, event.key, event.code, location, and modifier states
Press any key and instantly see its event.key, event.code, keyCode, which, location, and modifier states — no more console-logging every event just to find the right value for your shortcut handler. And everything runs in your browser. Nothing gets uploaded.
How It Works
The page listens for keydown events on the document. When you press a key, the browser fires a KeyboardEvent object packed with properties — key name, physical code, legacy keyCode number, location flag, and modifier booleans. This tool reads them all and displays each value instantly so you can copy exactly what you need for your code.
Examples
Detecting the Escape Key for a Modal
You want to close a popup when the user hits Escape. Press it here to confirm the right values.
Press: Escape key
key: "Escape"
code: "Escape"
keyCode: 27
which: 27
location: 0
Telling Left Shift from Right Shift
Building a game where left and right Shift do different things? The location property is what you need. Left Shift returns location 1, right Shift returns 2. Same keyCode, different location.
Press: Left Shift
key: "Shift"
code: "ShiftLeft"
keyCode: 16
location: 1 (LEFT)
Capturing Ctrl+S to Save a Document
You need the exact event properties to intercept the browser's default save behavior.
Press: Ctrl + S
key: "s"
code: "KeyS"
keyCode: 83
ctrlKey: true
shiftKey: false
Who Uses This
Look up keyCode values when building keyboard shortcuts, form validation, or custom hotkeys in web apps.
Map WASD, arrow keys, and spacebar to in-game actions — need exact codes for each key on every browser.
Verify that keyboard interactions fire the expected events, especially when testing accessibility or shortcut features.
Learn how JavaScript keyboard events work by seeing real values update live — beats reading documentation alone.
Common Mistakes
keyCode is deprecated. It still works, but event.key and event.code are more readable and consistent across keyboards. Use event.key === "Escape" instead of event.keyCode === 27 for anything new.
event.key gives you what the key produces ("a" or "A" depending on Shift). event.code gives you the physical key ("KeyA" always). If you're building layout-independent controls (like WASD movement), use code. For text input, use key.
The Meta key is Command on Mac and the Windows key on PC. event.metaKey reads true for both, but many Windows users expect Ctrl-based shortcuts, not Meta-based. Test on both platforms or check navigator.platform to pick the right modifier.
Technical Details
- Processing: 100% client-side — no keystrokes leave your browser
- Browser Support: Chrome, Firefox, Safari, Edge (all modern versions)
- Events Captured: keydown (key, code, keyCode, which, location, modifiers)
- History: Last 10 keypresses stored in-memory only, cleared on page refresh
Frequently Asked Questions
What is event.keyCode in JavaScript?
event.keyCode is a number that represents the physical key you pressed. The "A" key always returns 65, whether or not Shift is held. It has been deprecated in favor of event.key and event.code, but every browser still supports it and tons of existing code relies on it.
What is the difference between event.key and event.code?
event.key tells you the character produced — pressing Shift+A gives "A" (uppercase). event.code tells you which physical key was pressed — it always returns "KeyA" for that key, even on a French AZERTY keyboard where the same key types "Q". Use key for text handling, code for position-based controls like games.
Why was keyCode deprecated?
The values were inconsistent across browsers and keyboard layouts. A semicolon key might return 186 in Chrome but 59 in Firefox. The newer key and code properties fix this by returning consistent, human-readable strings. That said, keyCode still works everywhere — it just is not recommended for new code.
How do I detect arrow keys in JavaScript?
The modern way: check event.key === "ArrowUp", "ArrowDown", "ArrowLeft", or "ArrowRight". The legacy way: keyCode 37 (left), 38 (up), 39 (right), 40 (down). Both work, but event.key is far easier to read in your code.
Can I detect key combinations like Ctrl+Shift+K?
Yes. The KeyboardEvent gives you boolean properties — ctrlKey, shiftKey, altKey, and metaKey. Check them alongside event.key: if (event.ctrlKey && event.shiftKey && event.key === "K"). This tool shows modifier states live so you can verify the exact combo before writing your handler.