Free tool · Developer tools
JavaScript keycode finder
This JavaScript keycode finder reads the key you press and shows every value a keydown handler can see. Pressing Enter gives key "Enter", code "Enter" and keyCode 13, plus lines such as event.key === "Enter" to paste into your code.
- Free
- No sign-up
- Runs in your browser
EnterkeyCode 13, code Enter. Press a key in the box to replace this.
- Example
- event.key
- "Enter"
- event.code
- "Enter"
- event.keyCode
- 13
- event.which
- 13
- event.location
- 0 (Standard)
- Modifiers held
- none
- event.repeat
- false
- By key (the character or action)
event.key === "Enter" - By code (the physical key)
event.code === "Enter" - Legacy keyCode (deprecated)
event.keyCode === 13 - In a switch statement
case "Enter":
How to use the JavaScript Keycode Finder
- Click the dashed box under Press any key here. It says Listening when it has focus.
- Press a key, or a shortcut such as Ctrl and S. The values update at once, and held modifiers are listed.
- Copy the condition you need from Code to paste. Prefer the key or code line over the keyCode line.
- To go the other way, type a number or a key name into Look up a key code or key name.
How do I find the keycode of a key in JavaScript?
A keydown event carries several properties, and the box above shows all of them. For Enter the values are key "Enter", code "Enter", keyCode 13 and which 13, with location 0, which the page names Standard. The conditions that follow from it are event.key === "Enter", event.code === "Enter", event.keyCode === 13.
The Space bar shows why the key value needs care. Its key is a single space character, so the condition is written event.key === " ", and its keyCode is 32. The page names it Space on screen so the value is not invisible. Tab is recorded without being blocked, so you can still move out of the box with the keyboard. Every other key is captured, which is why the arrow keys do not scroll the page while you test them.
The same table works in reverse. Typing 32 into the lookup finds Space, typing 13 finds Enter, and a number with no key behind it gets a plain answer: "No key in the table has the code 999. Press the key in the box above to read its code from your own keyboard."
Should I use event.key, event.code or event.keyCode?
The W3C UI Events specification calls keyCode obsolete and tells authors to use the key attribute in its place, so the page prints that condition last. The two modern properties answer different questions. The key property is the character or action a key produces, so it changes with the layout and the modifiers. The code property names the physical key and ignores both. The W3C code list gives the example of the physical Q key: it reports code "KeyQ" on every layout, and it types q with a US layout but a with a French one.
That is why a shortcut for typed text should use key, and a game that moves with the W, A, S and D keys should use code. Hold Shift and press S and you get key "S" with code "KeyS" while keyCode stays 83. For a Ctrl and S shortcut the page offers event.ctrlKey && event.key === "s", and when Shift is held as well it becomes event.ctrlKey && event.shiftKey && event.key === "S", since the key is now a capital letter.
Modifier keys have a side. Pressing the left Shift key gives key "Shift", code "ShiftLeft", keyCode 16 and location 1, named Left in the list of locations, while the right key gives location 2 and code "ShiftRight". Only code and location tell the two apart, because key and keyCode are the same for both.
JavaScript keycode finder table: keyCode values of common keys
Digits use their ASCII code, so the key 0 is 48 and 9 is 57. Letters use the code of the capital letter, so A is 65 and Z is 90, whether Shift is held or not. The table lists the other keys the lookup knows. The punctuation codes are the values for a US layout, and the W3C UI Events specification lists them as values that can differ by layout, so test them on the keyboards you care about before relying on them.
| Key | event.key | event.code | keyCode |
|---|---|---|---|
| Backspace | Backspace | Backspace | 8 |
| Tab | Tab | Tab | 9 |
| Enter | Enter | Enter | 13 |
| Shift | Shift | ShiftLeft | 16 |
| Control | Control | ControlLeft | 17 |
| Alt | Alt | AltLeft | 18 |
| Caps Lock | CapsLock | CapsLock | 20 |
| Escape | Escape | Escape | 27 |
| Space | " " | Space | 32 |
| Page Up | PageUp | PageUp | 33 |
| Page Down | PageDown | PageDown | 34 |
| End | End | End | 35 |
| Home | Home | Home | 36 |
| Arrow Left | ArrowLeft | ArrowLeft | 37 |
| Arrow Up | ArrowUp | ArrowUp | 38 |
| Arrow Right | ArrowRight | ArrowRight | 39 |
| Arrow Down | ArrowDown | ArrowDown | 40 |
| Delete | Delete | Delete | 46 |
| F1 | F1 | F1 | 112 |
| Semicolon | ; | Semicolon | 186 |
| Equals sign | = | Equal | 187 |
| Comma | , | Comma | 188 |
| Minus | - | Minus | 189 |
| Period | . | Period | 190 |
| Forward slash | / | Slash | 191 |
| Backtick | ` | Backquote | 192 |
| Opening bracket | [ | BracketLeft | 219 |
| Backslash | \ | Backslash | 220 |
| Closing bracket | ] | BracketRight | 221 |
| Single quote | ' | Quote | 222 |
Use it with
- CPS Test: clicks per second test.
- Typing Speed Test: WPM and accuracy test.
- Gamepad Tester: check controller buttons, sticks and drift in the browser.
Questions
How do I get the keycode of a key press in JavaScript?
Add a keydown listener and read event.keyCode, or press the key in the box on this page. Enter gives 13, Escape gives 27 and Space gives 32.
Is event.keyCode deprecated?
Yes. The W3C UI Events specification lists keyCode among obsolete attributes and asks authors to use event.key, and event.code is the choice when the physical key matters.
What is the difference between event.key and event.code?
The key property is the character or action produced and depends on layout and modifiers. The code property names the physical key, so it stays the same on every layout.
How do I detect Ctrl+S or Cmd+S?
Press the shortcut in the box and copy the last line, for example event.ctrlKey && event.key === "s". Use event.metaKey in place of event.ctrlKey when the shortcut uses the Meta key.
Why does the arrow key not scroll the page here?
The box captures every key except Tab, and stops the default action, so the page stays still while you test. Click outside the box to scroll again.
Does the page send my key presses anywhere?
No. The box listens only while it has focus, and the values are read and shown in your tab without being stored or sent.
Sources
The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.