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. 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. 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. 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. 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.

PropertyPressing AWhat it meansStatus
event.keya (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.codeKeyAThe physical key, named after its place on a US keyboard. Stays the same in any layout and with Shift.Current standard
event.keyCode65An older number for the key. Some values differ between browsers and operating systems.Deprecated
event.which65The same number as keyCode on keydown and keyup.Deprecated
event.location0Where 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.

Detect a key press in JavaScriptJavaScript
// 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.

KeykeyCodeevent.keyevent.codeNotes
Common keys
Backspace8BackspaceBackspace
Tab9TabTab
Enter13EnterEnter
Esc27EscapeEscape
Space32" "Space
Insert45InsertInsert
Delete46DeleteDelete
Arrow and navigation keys
Left arrow37ArrowLeftArrowLeft
Up arrow38ArrowUpArrowUp
Right arrow39ArrowRightArrowRight
Down arrow40ArrowDownArrowDown
Page Up33PageUpPageUp
Page Down34PageDownPageDown
End35EndEnd
Home36HomeHome
Modifier keys
Left Shift16ShiftShiftLeft
Right Shift16ShiftShiftRight
Left Ctrl17ControlControlLeft
Right Ctrl17ControlControlRight
Left Alt (Option on a Mac)18AltAltLeft
Right Alt18AltAltRightOn layouts with AltGr, key is "AltGraph".
Left Windows or Command key91MetaMetaLeftFirefox on a Mac can report 224.
Right Windows or Command key92MetaMetaRight93 in Chrome on a Mac. Firefox on a Mac can report 224.
Caps Lock20CapsLockCapsLock
Menu key93ContextMenuContextMenu
Letter keys
A65aKeyA
B66bKeyB
C67cKeyC
D68dKeyD
E69eKeyE
F70fKeyF
G71gKeyG
H72hKeyH
I73iKeyI
J74jKeyJ
K75kKeyK
L76lKeyL
M77mKeyM
N78nKeyN
O79oKeyO
P80pKeyP
Q81qKeyQ
R82rKeyR
S83sKeyS
T84tKeyT
U85uKeyU
V86vKeyV
W87wKeyW
X88xKeyX
Y89yKeyY
Z90zKeyZ
Number keys (top row)
0480Digit0
1491Digit1
2502Digit2
3513Digit3
4524Digit4
5535Digit5
6546Digit6
7557Digit7
8568Digit8
9579Digit9
Function keys
F1112F1F1
F2113F2F2
F3114F3F3
F4115F4F4
F5116F5F5
F6117F6F6
F7118F7F7
F8119F8F8
F9120F9F9
F10121F10F10
F11122F11F11
F12123F12F12
Number pad (Num Lock on)
Number pad 0960Numpad0
Number pad 1971Numpad1
Number pad 2982Numpad2
Number pad 3993Numpad3
Number pad 41004Numpad4
Number pad 51015Numpad5
Number pad 61026Numpad6
Number pad 71037Numpad7
Number pad 81048Numpad8
Number pad 91059Numpad9
Number pad *106*NumpadMultiply
Number pad +107+NumpadAdd
Number pad -109-NumpadSubtract
Number pad .110.NumpadDecimal
Number pad /111/NumpadDivide
Number pad Enter13EnterNumpadEnter
Num Lock144NumLockNumLock
Punctuation and symbol keys
Semicolon186;Semicolon59 in Firefox.
Equals sign187=Equal61 in Firefox.
Comma188,Comma
Minus (dash)189-Minus173 in Firefox.
Period190.Period
Forward slash191/Slash
Backtick192`Backquote
Open bracket219[BracketLeft
Backslash220\Backslash
Close bracket221]BracketRight
Single quote222'Quote
Lock and system keys
Pause / Break19PausePause
Print Screen44PrintScreenPrintScreenOn Windows, only keyup fires.
Scroll Lock145ScrollLockScrollLock

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.