Live key event
Values from the most recent keyboard event
--
- event.key
- --
- event.code
- --
- keyCode (deprecated)
- --
- which (deprecated)
- --
- location
- --
- modifiers
- --
- repeat
- --
- event type
- --
- timeStamp
- --
Last 20 events
| type | key | code | keyCode | modifiers |
|---|
Press a key and the viewer shows everything a browser reports about it: the character in event.key, the physical position in event.code, the legacy keyCode and which numbers, the location, the modifiers held and whether it was an auto-repeat. The last twenty events stay in the history, one click copies the last event as JSON, and the reference table below lets you search any code by name, number or key. Repeat the mac keyboard test a few times for a more reliable reading.
Values from the most recent keyboard event
--
Last 20 events
| type | key | code | keyCode | modifiers |
|---|
| event.code | keyCode | Key |
|---|
Every press on your keyboard fires an event in the DOM, and the JavaScript keycode is the number that event carries to tell your script which key you hit. Use this guide as a lookup tool for any value, see how JavaScript keycodes behave in each browser, and decide when to skip the number entirely and read e.code or e.key instead.
A keycode is an integer on a KeyboardEvent that web developers read inside a handler. For letters and digits it matches the ASCII value, so uppercase A through Z map to 65-90. Other keyboard keys, such as arrows, function keys and punctuation, follow the older Windows virtual-key numbering. The W3C standard now marks the keyCode property as legacy, but millions of pages still depend on those numbers, and JavaScript keycodes still turn up in old code constantly. Every JavaScript keycode arrives through keyboard events, so the same press can report different numbers on Chrome, Firefox and Safari. Try the finger speed test next if you want another angle on how your keyboard behaves.
A keycodes decoder simply runs the lookup in reverse: give it 75 and it answers "K". Because the mapping is fixed for ordinary keys, you can decode a list of numbers by hand with the table below, or encode text the same way. When a logged keydown shows 75, the lookup tells you the K key was pressed.
The table lists the most-used key codes on a standard US keyboard. Letters (65-90) and digits (48-57) follow ASCII and are left out to keep the list short. Checking iso or ansi keyboard? The tool runs in your browser and takes about a minute.
| Key | Keycode | Key | Keycode |
|---|---|---|---|
| Backspace | 8 | Arrow Down | 40 |
| Tab | 9 | Print Screen | 44 |
| Enter | 13 | Insert | 45 |
| Shift | 16 | Delete | 46 |
| Ctrl (Control) | 17 | Meta Key | 91 |
| Alt | 18 | Context Menu | 93 |
| Pause/Break | 19 | Numpad 0 | 96 |
| Caps Lock | 20 | Multiply | 106 |
| Escape | 27 | Subtract | 109 |
| Space Bar | 32 | Decimal Point | 110 |
| Page Up | 33 | Divide | 111 |
| Page Down | 34 | F1 | 112 |
| End | 35 | F12 | 123 |
| Home | 36 | Num Lock | 144 |
| Arrow Left | 37 | Scroll Lock | 145 |
| Arrow Up | 38 | Semi-colon | 186 |
| Arrow Right | 39 | Equal Sign | 187 |
| Comma | 188 | Dash | 189 |
| Period | 190 | Forward Slash | 191 |
| Grave Accent | 192 | Open Bracket | 219 |
| Back Slash | 220 | Close Bracket | 221 |
| Single Quote | 222 | Enter (Numpad) | 13 |
The numpad runs from 96 (Numpad 0) to 105 (Numpad 9), and function keys continue from F1 at 112 to F12 at 123. Press the left arrow and you get 37, the right arrow gives 39, the up arrow gives 38 and the down arrow gives 40.
Editing keys are just as predictable. The Backspace key (8) deletes to the left and the Delete key (46) deletes to the right, while Tab (9) moves focus and Escape (27) closes dialogs. Home (36) and End (35) jump to the start or finish of a line, and Insert (45) toggles overwrite mode. The Shift key reports 16, and holding Shift with a letter changes the character but not the number. A comma is 188, and Shift plus comma still reports 188, so the Shift state must be read from the event's shiftKey flag.
Take the word KEYS. Each letter's ASCII code equals its keycode, so it encodes to 75, 69, 89, 83. To decode, you swap each number back for its letter: 75 is K, 69 is E, 89 is Y and 83 is S. In a keyboard handler, logging 75, 69, 89, 83 and decoding them back to KEYS shows which keys were typed. The substitution is a simple cipher that breaks the moment Unicode characters, a lowercase letter (charCode 107 for k, but key code 75) or a hex value such as 0x4B (the same decimal 75) enter the picture.
Marguerite is wiring up a small canvas game for a school club, and the decision in front of her is simple: should the movement handler test e.keyCode or e.code? She starts by pressing the four movement keys in a key-event logger and writing down what comes back.
| Press | keyCode | e.key | e.code |
|---|---|---|---|
| W | 87 | w | KeyW |
| A | 65 | a | KeyA |
| S | 83 | s | KeyS |
| D | 68 | d | KeyD |
She cross-checks the numbers without trusting the logger: letters follow ASCII, and the character codes of W, A, S and D are 87, 65, 83 and 68, which match. Her first handler compares e.keyCode === 87 and moves the player up. On her own laptop it works, so she tests with her club mate's French AZERTY keyboard.
The sensitivity rerun is the revealing part. On AZERTY, the key sitting where a US keyboard has W prints "z", and Chrome reports keyCode 90 for it, so the === 87 test never fires and the player cannot move up. Reading e.code instead, that same physical key reports "KeyW" with e.key "z", so the controls keep the WASD shape under the fingers on any layout. The number to watch is the one tied to the position, not the letter.
There is a caveat. A physical-position check is wrong for a text field, where the user wants the character they typed, so Marguerite keeps e.key for the name input and e.code for movement. She adds the arrow keys as a second binding using their usual fallback values, 37, 38, 39 and 40, from the lookup. The W3C UI Events specification lists keyCode as legacy, which settles it: she ships the e.code version and keeps the numbers only as a fallback comment.
Three events report a key. The keydown event fires when you press, the keyup event fires on release, and the keypress event (also deprecated) fires only for keys that produce a character. Attach a listener with addEventListener and read the value from the event object:
document.addEventListener('keydown', (e) => {
console.log(e.key, e.code, e.which, e.keyCode);
});
Run it, then press any key in the page. Each key has a name, a character and a keycode, so check which key you need before you read the key, and press the same key twice to confirm the key code is stable. Holding a key repeats keydown events but sends one keyup, so key events are not always paired. A handler on a virtual keyboard may see 229 and "Unidentified" (the value KeyboardEvent.key falls back to when the browser cannot name a key; KeyboardEvent.code is then empty), because an IME (input method editor) is composing the input, and no single physical key produced the character. Keycodes are also a virtual layer, unlike the hardware scancode a keyboard sends to the operating system.
The old event.keyCode (also written e.keyCode), e.which and charCode are deprecated, and each behaves differently between browsers. Use the properties below for new work.
| Property | Returns | Status |
|---|---|---|
| e.keyCode / e.which | Number such as 65 | Deprecated |
| e.code | Physical key, such as KeyA | Standard |
| e.key | Character produced, such as "a" | Standard |
KeyboardEvent.code reports the physical key regardless of layout, while KeyboardEvent.key reports the character. A modifier key like the shift key or alt key changes e.key but not e.code.
Printable keys in standard position are not consistent. Chrome and Safari pick the value from the input character, using the US keyboard layout when possible, while Firefox reads it from the ASCII character the key produces. Windows, Mac and Linux each add a twist, so test on the platforms your visitors use.
| Platform | Browser | Semi-colon | Equal Sign | Dash |
|---|---|---|---|---|
| Windows | Chrome | 186 | 187 | 189 |
| Windows | Firefox | 59 | 61 | 173 |
| Windows | Internet Explorer | 186 | 187 | 189 |
| Mac | Chrome | 186 | 187 | 189 |
| Mac | Safari | 186 | 187 | 189 |
| Mac | Firefox | 59 | 61 | 173 |
| Linux | Chrome | 186 | 187 | 189 |
| Linux | Firefox | 59 | 61 | 173 |
The meta key shows the same split: Chrome and Safari report 91 for the left Command key on a Mac, while Firefox reports 224.
Switch to a Russian keyboard layout and the Period and Slash keys can both report 190 in Firefox, even though the physical keys differ. A non-ASCII layout also hands the browser an input method that cannot be mapped to a single key. When you must tell physical keys apart, use e.code instead of the number. The platform scancodes below are not the JavaScript key code values, and e.code hides them:
| e.code value | Windows scancode | Mac keycode | Linux (X11) keycode |
|---|---|---|---|
| Escape | 0x0001 | 0x0035 | 0x0009 |
| Digit1 | 0x0002 | 0x0012 | 0x000A |
| Enter | 0x001C | 0x0024 | 0x0024 |
Chrome and Firefox return the same e.code string for each row on Windows, Mac and Linux, even though the platform values differ, which is why code is the safer property to rely on across layouts. A KeyboardEvent.code string such as "Escape" is identical on Windows and Linux, while only the platform number changes.
It is the number a KeyboardEvent carries in its keyCode property to identify the key that was pressed. Letters and digits match their ASCII values, and other keys follow the older Windows virtual-key numbers.
Yes. keyCode, which and charCode are deprecated, and they behave differently between browsers. Use event.code for the physical key and event.key for the character it produces.
Enter reports 13. The numpad Enter key also reports 13, so e.code (Enter or NumpadEnter) is needed to tell them apart.
Replace each number with the key it stands for: 65-90 are the letters A-Z, 48-57 are the digits 0-9, and the rest come from a keycode table. Paste the list into the tool above to do it automatically.
Chrome and Safari pick the value from the input character on a US layout, while Firefox reads it from the ASCII character the key produces, so punctuation such as the semi-colon can report 186 or 59.
An input method editor (IME) is composing the text, so the event reports 229 and the key as Unidentified instead of a single physical key.
No. For security reasons a script cannot type real keyboard keys; it can only dispatch synthetic events that the browser treats as untrusted.