Skip to the test
KeyboardTest

JavaScript Keycodes: Key Code List for KeyboardEvent

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.

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

Recent key events
typekeycodekeyCodemodifiers

event.code reference

Standard event.code values with legacy keyCode
event.codekeyCodeKey

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.

JavaScript Key Codes: What a Keycode Number Tells You

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.

Keycodes Decoder Basics: From Key to Number

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.

JavaScript Keycode Table: Keyboard Codes for Every Common Key

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.

JavaScript Keycode Table: Keyboard Codes for Every Common Key
KeyKeycodeKeyKeycode
Backspace8Arrow Down40
Tab9Print Screen44
Enter13Insert45
Shift16Delete46
Ctrl (Control)17Meta Key91
Alt18Context Menu93
Pause/Break19Numpad 096
Caps Lock20Multiply106
Escape27Subtract109
Space Bar32Decimal Point110
Page Up33Divide111
Page Down34F1112
End35F12123
Home36Num Lock144
Arrow Left37Scroll Lock145
Arrow Up38Semi-colon186
Arrow Right39Equal Sign187
Comma188Dash189
Period190Forward Slash191
Grave Accent192Open Bracket219
Back Slash220Close Bracket221
Single Quote222Enter (Numpad)13

Numpad and Function Keys in the Keycode List

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.

Decode and Encode Keycodes: A Worked ASCII Code Example

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.

Binding WASD Movement Using JavaScript Key Codes

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.

Binding WASD Movement Using JavaScript Key Codes
PresskeyCodee.keye.code
W87wKeyW
A65aKeyA
S83sKeyS
D68dKeyD

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.

Keydown Event, Keyup Event and Keypress Event Key Codes

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.

Keycodes vs e.code vs e.key: Replacing a Deprecated Property

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.

Keycodes vs e.code vs e.key: Replacing a Deprecated Property
PropertyReturnsStatus
e.keyCode / e.whichNumber such as 65Deprecated
e.codePhysical key, such as KeyAStandard
e.keyCharacter 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.

Browser Compatibility: Keycodes Across Chrome, Firefox and Safari

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.

Browser Compatibility: Keycodes Across Chrome, Firefox and Safari
PlatformBrowserSemi-colonEqual SignDash
WindowsChrome186187189
WindowsFirefox5961173
WindowsInternet Explorer186187189
MacChrome186187189
MacSafari186187189
MacFirefox5961173
LinuxChrome186187189
LinuxFirefox5961173

The meta key shows the same split: Chrome and Safari report 91 for the left Command key on a Mac, while Firefox reports 224.

  • On Windows, the native virtual keycode decides the value for a-z and 0-9 in every browser.
  • On Mac, Chrome and Safari follow the US keyboard layout, while Firefox maps from the ASCII character.
  • On Linux, Chrome and Firefox rely on the active keyboard layout.
  • On Windows, Internet Explorer and Chrome agree for punctuation, but Firefox differs from both, and a Windows laptop with a numeric pad adds its own Numpad keys.
  • Linux desktops let each user switch layouts mid-session, so one Linux key can report two different numbers in a day.

Keyboard Layout and IME Differences

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:

Keyboard Layout and IME Differences
e.code valueWindows scancodeMac keycodeLinux (X11) keycode
Escape0x00010x00350x0009
Digit10x00020x00120x000A
Enter0x001C0x00240x0024

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.

Frequently asked questions

What is a JavaScript keycode?

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.

Is event.keyCode deprecated?

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.

What is the keycode for the Enter key?

Enter reports 13. The numpad Enter key also reports 13, so e.code (Enter or NumpadEnter) is needed to tell them apart.

How do I decode a list of keycodes?

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.

Why do keycodes differ between browsers?

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.

Why does a virtual keyboard report 229?

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.

Can JavaScript press keys for me?

No. For security reasons a script cannot type real keyboard keys; it can only dispatch synthetic events that the browser treats as untrusted.

Comments and feedback