Find Any Key Code
Press any key to instantly get its JavaScript event properties — key, code, keyCode, charCode, and more.
Click here, then press any key
Detects all keyboard events in real-time
// Press a key to generate snippet
What Is a Key Code Finder?
A key code finder is a tool that shows you the exact JavaScript event properties generated when you press any key on your keyboard. Press a key and it instantly displays the values for event.key, event.code, keyCode, charCode, and which, all in one place.
Developers need these values when building keyboard shortcuts, game controls, form validation, or any feature that responds to keyboard input. Instead of guessing a key's code or searching through documentation tables, you press the key and get the exact values your code needs.
Our key code finder also detects modifier key states like Shift, Ctrl, Alt, Cmd, CapsLock, and NumLock, so you can check how key combinations behave, not just individual keys.
How to Use the Key Code Finder
-
Step 1: Press Any Key
Click on the tool area and press the key you want to look up. The event properties appear instantly on screen.
-
Step 2: Read the Values
You'll see an event.key, event.code, keyCode, charCode, and which for the key you pressed. Each value is displayed separately, so you can grab exactly the one you need.
-
Step 3: Check Modifier States
If you need to test a key combination, hold down Shift, Ctrl, Alt, or Cmd while pressing the key. The tool shows which modifiers were active during the press.
-
Step 4: Copy and Use
Pick the value that fits your use case and drop it into your code. Use event.key or event.code for modern projects. Fall back to keyCode only if you're supporting older browsers.
event.key vs event.code vs keyCode: What's the Difference?
These three properties all come from the same keyboard event, but they return different things and are meant for different situations.
event.key
Returns the character the key produces. It changes based on your keyboard layout and active modifiers. Use it for text input and form handling.
event.code
Returns the physical position of the key. It stays the same regardless of layout or language. Use it for game controls and positional shortcuts.
keyCode
Returns a numeric code. It's deprecated because values were inconsistent across browsers. Avoid it in new projects, but you'll still find it in older codebases.
| event.key | event.code | keyCode | |
|---|---|---|---|
| Returns | Character value | Physical key location | Numeric code |
| Press "a" | "a" | "KeyA" | 65 |
| Shift + "a" | "A" | "KeyA" | 65 |
| "a" on AZERTY | "q" | "KeyA" | 65 |
| Enter | "Enter" | "Enter" | 13 |
| Left Shift | "Shift" | "ShiftLeft" | 16 |
| Right Shift | "Shift" | "ShiftRight" | 16 |
| Space | " " | "Space" | 32 |
| Status | Current standard | Current standard | Deprecated |
| Best for | Text input, forms | Game controls, shortcuts | Legacy code only |
Quick rule: use event.key when you care about what character was typed, event.code when you care about which physical key was pressed, and keyCode only when maintaining old code.
Common Key Codes Reference Table
A quick lookup for the keys developers search for most often.
| Key | event.key | event.code | keyCode |
|---|---|---|---|
| Enter | "Enter" | "Enter" | 13 |
| Escape | "Escape" | "Escape" | 27 |
| Space | " " | "Space" | 32 |
| Tab | "Tab" | "Tab" | 9 |
| Backspace | "Backspace" | "Backspace" | 8 |
| Delete | "Delete" | "Delete" | 46 |
| Arrow Up | "ArrowUp" | "ArrowUp" | 38 |
| Arrow Down | "ArrowDown" | "ArrowDown" | 40 |
| Arrow Left | "ArrowLeft" | "ArrowLeft" | 37 |
| Arrow Right | "ArrowRight" | "ArrowRight" | 39 |
| Shift (Left) | "Shift" | "ShiftLeft" | 16 |
| Shift (Right) | "Shift" | "ShiftRight" | 16 |
| Ctrl (Left) | "Control" | "ControlLeft" | 17 |
| Alt (Left) | "Alt" | "AltLeft" | 18 |
| Cmd / Meta | "Meta" | "MetaLeft" | 91 |
| CapsLock | "CapsLock" | "CapsLock" | 20 |
| F1 | "F1" | "F1" | 112 |
| F5 | "F5" | "F5" | 116 |
| F11 | "F11" | "F11" | 122 |
| F12 | "F12" | "F12" | 123 |
| A | "a" | "KeyA" | 65 |
| Z | "z" | "KeyZ" | 90 |
| 0 | "0" | "Digit0" | 48 |
| 9 | "9" | "Digit9" | 57 |
This covers the keys that developers look up most often. For any key not listed here, just press it in the tool above and get the values instantly.
How to Handle Keyboard Events in JavaScript
There are three keyboard events in JavaScript: keydown fires when a key is pressed, keyup fires when it's released, and keypress fires for character-producing keys. keypress is deprecated, so stick with keydown and keyup for all new code.
Here's a basic setup using an event.key:
document.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
// handle Enter key
}
});
If you're building something where physical key position matters, like game controls, use an event.code instead:
document.addEventListener("keydown", (event) => {
if (event.code === "KeyW") {
// move forward, works on any keyboard layout
}
});
To detect key combinations, check the modifier properties along with the key:
document.addEventListener("keydown", (event) => {
if (event.ctrlKey && event.key === "s") {
event.preventDefault();
// custom save action
}
});
One thing to watch out for: always call the event.preventDefault() when overriding browser shortcuts like Ctrl+S or Ctrl+P. Without it, the browser's default action fires alongside your custom handler.
Frequently Asked Questions
Because it returned inconsistent values across different browsers and operating systems. The same key could produce different numeric codes depending on the platform. event.key and event.code were introduced to fix this and are now the recommended standard.
The Fn key is handled at the hardware level before the signal reaches your browser. No browser-based tool can detect it because the operating system never receives a separate event for it.
Yes. event.key will return the character your layout produces, and the event.code will return the physical key position. This is exactly why both properties exist: to handle different layouts correctly.
keydown fires the moment you press a key. keyup fires when you release it. For most use cases like shortcuts and controls, keydown is what you want. keyup is useful when you need to know the exact moment a key was released, like stopping character movement in a game.
Yes. Hold down any modifier (Shift, Ctrl, Alt, Cmd) and press another key. The tool shows both the key value and which modifiers were active during the press.
Because event.key is affected by modifiers and keyboard layout. Press "a" and you get "a". Hold Shift and press "a" and you get "A". Same physical key, different event.key values. If you need consistency regardless of modifiers, use event.code instead.