JavaScript Keycode Finder
Press any key to see its JavaScript keyCode, event.key, and event.code. Then copy a keydown listener that checks for that key, including Ctrl, Shift, Alt, and Meta combinations.
Press any key
Its keyCode, key, and code will show here.
Press any key to see its codes. Click the box first to also capture Tab and keys the browser uses for shortcuts.
What is a JavaScript keycode?
When you press a key, the browser sends a keydown event to the page, and a keyup event when you let go. The event says which key it was in a few ways. The keyCode is the oldest: a number for each key, such as 13 for Enter or 65 for A.
Newer code uses event.key, which gives the character or key name ("a", "Enter"), and event.code, which names the physical key ("KeyA", "Enter"). This finder shows all of them for any key you press, so you do not have to log events to the console to find out.
Why use our keycode finder
- ·Every value at once. keyCode, key, code, which, location, modifier flags, and the Unicode code point, each with a Copy button.
- ·Code you can paste. A keydown listener for the exact key or shortcut you pressed, written with key, code, or keyCode.
- ·Shortcut keys too. Click the box to capture Tab, F5, Space, and other keys the browser normally acts on.
- ·A full key code list. Look up any key below without pressing it, with the Firefox values that differ.
- ·Free. No signup, nothing to install, and nothing sent to a server.
How to find a JavaScript keycode
- 1
Press the key
Press any key on your keyboard. Its keyCode appears in large numbers, with the key name and any modifier keys you held, like Ctrl or Shift.
- 2
Click the box for shortcut keys
Keys like Tab, Space, F5, and the arrow keys also do things in the browser. Click the box first so every key is captured. Press Esc twice, or click outside the box, to go back to the page.
- 3
Read and copy the values
The table under the box shows event.key, event.code, event.keyCode, event.which, event.location, the modifier flags, and the Unicode code point. Each value has its own Copy button.
- 4
Copy the JavaScript
Pick whether the code should check event.key, event.code, or event.keyCode, then copy the keydown listener. It includes the modifier keys you held, so Ctrl + S gives you a check for Ctrl + S.
event.key vs event.code vs keyCode
A keyboard event carries several values that sound alike but answer different questions. Here is what each one reports when you press the A key on a US keyboard.
| Property | Pressing A | What it means | Status |
|---|---|---|---|
| event.key | a (A with Shift) | The character the key types, or a name like Enter or ArrowUp. Changes with Shift and with the keyboard layout. | Current standard |
| event.code | KeyA | The physical key, named after its place on a US keyboard. Stays the same in any layout and with Shift. | Current standard |
| event.keyCode | 65 | An older number for the key. Some values differ between browsers and operating systems. | Deprecated |
| event.which | 65 | The same number as keyCode on keydown and keyup. | Deprecated |
| event.location | 0 | Where the key is: 0 standard, 1 left, 2 right, 3 number pad. Tells left Shift from right Shift. | Current standard |
Use event.key when you care about what the person typed, like Enter to submit or Ctrl + S to save. Use event.code when you care about where the key is, like WASD to move in a game. Only use keyCode when you have to support very old browsers or work in older code that already uses it.
// Typed characters and named keys: use event.key
document.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
console.log("Enter pressed");
}
if ((event.ctrlKey || event.metaKey) && event.key === "s") {
event.preventDefault(); // Stop the browser's Save dialog
console.log("Save shortcut pressed");
}
});
// Physical keys, like WASD game controls: use event.code
document.addEventListener("keydown", (event) => {
if (event.code === "KeyW") {
console.log("Move forward");
}
});JavaScript key code list
These are the values Chrome, Edge, and Safari report on keydown for a US keyboard on Windows. The event.key column shows the value without Shift. Where Firefox or a Mac reports something different, it is noted in the last column.
| Key | keyCode | event.key | event.code | Notes |
|---|---|---|---|---|
| Common keys | ||||
| Backspace | 8 | Backspace | Backspace | |
| Tab | 9 | Tab | Tab | |
| Enter | 13 | Enter | Enter | |
| Esc | 27 | Escape | Escape | |
| Space | 32 | " " | Space | |
| Insert | 45 | Insert | Insert | |
| Delete | 46 | Delete | Delete | |
| Arrow and navigation keys | ||||
| Left arrow | 37 | ArrowLeft | ArrowLeft | |
| Up arrow | 38 | ArrowUp | ArrowUp | |
| Right arrow | 39 | ArrowRight | ArrowRight | |
| Down arrow | 40 | ArrowDown | ArrowDown | |
| Page Up | 33 | PageUp | PageUp | |
| Page Down | 34 | PageDown | PageDown | |
| End | 35 | End | End | |
| Home | 36 | Home | Home | |
| Modifier keys | ||||
| Left Shift | 16 | Shift | ShiftLeft | |
| Right Shift | 16 | Shift | ShiftRight | |
| Left Ctrl | 17 | Control | ControlLeft | |
| Right Ctrl | 17 | Control | ControlRight | |
| Left Alt (Option on a Mac) | 18 | Alt | AltLeft | |
| Right Alt | 18 | Alt | AltRight | On layouts with AltGr, key is "AltGraph". |
| Left Windows or Command key | 91 | Meta | MetaLeft | Firefox on a Mac can report 224. |
| Right Windows or Command key | 92 | Meta | MetaRight | 93 in Chrome on a Mac. Firefox on a Mac can report 224. |
| Caps Lock | 20 | CapsLock | CapsLock | |
| Menu key | 93 | ContextMenu | ContextMenu | |
| Letter keys | ||||
| A | 65 | a | KeyA | |
| B | 66 | b | KeyB | |
| C | 67 | c | KeyC | |
| D | 68 | d | KeyD | |
| E | 69 | e | KeyE | |
| F | 70 | f | KeyF | |
| G | 71 | g | KeyG | |
| H | 72 | h | KeyH | |
| I | 73 | i | KeyI | |
| J | 74 | j | KeyJ | |
| K | 75 | k | KeyK | |
| L | 76 | l | KeyL | |
| M | 77 | m | KeyM | |
| N | 78 | n | KeyN | |
| O | 79 | o | KeyO | |
| P | 80 | p | KeyP | |
| Q | 81 | q | KeyQ | |
| R | 82 | r | KeyR | |
| S | 83 | s | KeyS | |
| T | 84 | t | KeyT | |
| U | 85 | u | KeyU | |
| V | 86 | v | KeyV | |
| W | 87 | w | KeyW | |
| X | 88 | x | KeyX | |
| Y | 89 | y | KeyY | |
| Z | 90 | z | KeyZ | |
| Number keys (top row) | ||||
| 0 | 48 | 0 | Digit0 | |
| 1 | 49 | 1 | Digit1 | |
| 2 | 50 | 2 | Digit2 | |
| 3 | 51 | 3 | Digit3 | |
| 4 | 52 | 4 | Digit4 | |
| 5 | 53 | 5 | Digit5 | |
| 6 | 54 | 6 | Digit6 | |
| 7 | 55 | 7 | Digit7 | |
| 8 | 56 | 8 | Digit8 | |
| 9 | 57 | 9 | Digit9 | |
| Function keys | ||||
| F1 | 112 | F1 | F1 | |
| F2 | 113 | F2 | F2 | |
| F3 | 114 | F3 | F3 | |
| F4 | 115 | F4 | F4 | |
| F5 | 116 | F5 | F5 | |
| F6 | 117 | F6 | F6 | |
| F7 | 118 | F7 | F7 | |
| F8 | 119 | F8 | F8 | |
| F9 | 120 | F9 | F9 | |
| F10 | 121 | F10 | F10 | |
| F11 | 122 | F11 | F11 | |
| F12 | 123 | F12 | F12 | |
| Number pad (Num Lock on) | ||||
| Number pad 0 | 96 | 0 | Numpad0 | |
| Number pad 1 | 97 | 1 | Numpad1 | |
| Number pad 2 | 98 | 2 | Numpad2 | |
| Number pad 3 | 99 | 3 | Numpad3 | |
| Number pad 4 | 100 | 4 | Numpad4 | |
| Number pad 5 | 101 | 5 | Numpad5 | |
| Number pad 6 | 102 | 6 | Numpad6 | |
| Number pad 7 | 103 | 7 | Numpad7 | |
| Number pad 8 | 104 | 8 | Numpad8 | |
| Number pad 9 | 105 | 9 | Numpad9 | |
| Number pad * | 106 | * | NumpadMultiply | |
| Number pad + | 107 | + | NumpadAdd | |
| Number pad - | 109 | - | NumpadSubtract | |
| Number pad . | 110 | . | NumpadDecimal | |
| Number pad / | 111 | / | NumpadDivide | |
| Number pad Enter | 13 | Enter | NumpadEnter | |
| Num Lock | 144 | NumLock | NumLock | |
| Punctuation and symbol keys | ||||
| Semicolon | 186 | ; | Semicolon | 59 in Firefox. |
| Equals sign | 187 | = | Equal | 61 in Firefox. |
| Comma | 188 | , | Comma | |
| Minus (dash) | 189 | - | Minus | 173 in Firefox. |
| Period | 190 | . | Period | |
| Forward slash | 191 | / | Slash | |
| Backtick | 192 | ` | Backquote | |
| Open bracket | 219 | [ | BracketLeft | |
| Backslash | 220 | \ | Backslash | |
| Close bracket | 221 | ] | BracketRight | |
| Single quote | 222 | ' | Quote | |
| Lock and system keys | ||||
| Pause / Break | 19 | Pause | Pause | |
| Print Screen | 44 | PrintScreen | PrintScreen | On Windows, only keyup fires. |
| Scroll Lock | 145 | ScrollLock | ScrollLock | |
Why keyCode values differ between browsers
keyCode was never fully standardized, so browsers and operating systems picked their own numbers for some keys. If a key check works in one browser but not another, one of these is usually the reason.
- ·Firefox uses different numbers for three keys. Firefox reports 59 for the semicolon, 61 for the equals sign, and 173 for the minus key. Chrome, Edge, and Safari report 186, 187, and 189. If your code checks these keyCodes, check both values or switch to event.key.
- ·The Windows and Command keys vary. The left Windows key and the left Command key on a Mac report 91. The right one reports 92 on Windows but 93 in Chrome on a Mac, and Firefox on a Mac can report 224 for both.
- ·The keyboard layout changes letter codes. On a French AZERTY keyboard, the key in the place of the US Q types an A, so event.key is a and keyCode is 65, while event.code is still KeyQ. Use event.code for game controls like WASD so they stay in the same place on every layout.
- ·Num Lock changes the number pad. With Num Lock off, the number pad 8 key reports event.key ArrowUp and keyCode 38, the same as the arrow key. Its event.code stays Numpad8, so you can still tell them apart.
- ·Phones and input methods report 229. Many on-screen keyboards on Android, and input methods (IME) for languages like Chinese and Japanese, send keydown with keyCode 229 and event.key Unidentified. The real text arrives through the input event instead.
Keys a web page cannot detect
If a key shows nothing in the finder, your own page will not see it either. These are the usual cases.
- ·Keys the operating system keeps. The Windows key opens the Start menu, and shortcuts like Alt + Tab, Alt + F4, and Cmd + Tab are handled by the operating system. The page may see the first key, but not the whole shortcut.
- ·Browser shortcuts that cannot be blocked. Chrome and Edge do not let a web page stop Ctrl + N, Ctrl + T, or Ctrl + W (Cmd on a Mac). The new window or tab opens before the page can react.
- ·The Fn key. Most laptops handle Fn inside the keyboard itself, so it never reaches the browser. You only see the key it changes, such as F5 or a volume key.
- ·Print Screen on Windows. Windows sends only a keyup for Print Screen. The finder still shows it, using the keyup event.
Frequently asked questions
- How do I find the keycode of a key in JavaScript?
- Press the key on this page and the keycode finder shows its keyCode, event.key, and event.code. In your own code, add a keydown listener with document.addEventListener and read event.key, event.code, or event.keyCode from the event it receives.
- What is the keyCode for Enter?
- Enter is keyCode 13, and its event.key is Enter. The Enter key on the number pad also reports keyCode 13, but its event.code is NumpadEnter instead of Enter.
- What are the keyCodes for the arrow keys?
- Left is 37, Up is 38, Right is 39, and Down is 40. Their event.key and event.code values are ArrowLeft, ArrowUp, ArrowRight, and ArrowDown.
- What are the keyCodes for Escape, Space, Tab, and Backspace?
- Escape is 27, Space is 32, Tab is 9, and Backspace is 8. Note that event.key for Space is a single space character (" "), not the word Space. Its event.code is Space.
- Is keyCode deprecated?
- Yes. keyCode, which, and charCode are all deprecated. Browsers still support them so old sites keep working, but new code should use event.key for the character typed and event.code for the physical key.
- What is the difference between event.key and event.code?
- event.key is what the key types, so it changes with Shift and the keyboard layout (a, A, or q on a French keyboard). event.code is the physical key and never changes (KeyA). Use key for text and shortcuts, and code for game controls.
- Why does keyCode show 229?
- 229 means the key press went through an input method (IME) or an on-screen keyboard, which is common on Android phones. The browser does not say which key it was. Skip these events by checking event.isComposing or keyCode 229, and read the typed text from the input event.
- Why does event.key show a strange character when I hold Option or Alt?
- On a Mac, Option types special characters, so Option + S gives ß instead of s. On some keyboards, AltGr does the same. For shortcuts with Option or Alt, check event.code (KeyS) instead of event.key.
- Why is the uppercase and lowercase keyCode the same?
- keyCode names the key, not the character, so A and a are both 65. event.key does change: it is a without Shift and A with Shift (or with Caps Lock on). Check event.shiftKey if you need to know whether Shift was held.
- What happened to charCode and the keypress event?
- charCode was only set on the keypress event, and both are deprecated. To read the character typed, use event.key on keydown, or the input event for text fields.
- Is anything I type sent anywhere?
- No. The keycode finder reads key events in your browser and nothing is sent to a server.