Skip to main content
ponderloop

JavaScript Key Code Finder

Press a key in the box to see its event.key, event.code, legacy keyCode and which, location, modifiers and repeat state, with a snippet to copy. The example, Enter, gives event.key “Enter”, event.code “Enter” and keyCode 13, so the check is if (event.key === 'Enter'). Prefer event.key (what the key types) or event.code (which physical key); keyCode and which are deprecated. The table lists 28 common keys. Everything runs in your browser and nothing you press is sent anywhere.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Press a key

Click the box or Tab to it, then press any key. Tab leaves the box as usual; to inspect Tab itself, tick the box below. Escape releases it.

Not listening. Click here or Tab to this box, then press a key.

Last key

Enter

event.key
Enter
The value the key produces, after layout and modifiers.
event.code
Enter
The physical key, the same whatever the layout.
event.keyCode
13
Deprecated number. Use key or code.
event.which
13
Deprecated, usually equal to keyCode.
event.location
0 (Standard)
Which copy of the key: standard, left, right or numpad.
Modifiers
None
Shift, Ctrl, Alt and Meta held while the key went down.
event.repeat
false
True while the key is held down and auto-repeating.

JavaScript to copy

Check event.key (The character or named key.)
if (event.key === 'Enter')
Check event.code (The physical key, whatever the layout.)
if (event.code === 'Enter')
Check keyCode (deprecated) (Only for old code you cannot change.)
if (event.keyCode === 13)

Recent keys

No keys pressed yet. Each entry reads key · code · keyCode, newest first.

    Common keys: event.key, event.code and keyCode

    Typical values on a US QWERTY keyboard. event.key and event.code come from the W3C UI Events key and code specifications; keyCode is the legacy number browsers still report and no specification defines it.
    Keyevent.keyevent.codekeyCode (legacy)Note
    Enter (main)EnterEnter13Typical value
    Enter (numpad)EnterNumpadEnter13Same key and keyCode as main Enter; code and location differ.
    Space" " (a space)Space32Typical value
    TabTabTab9Typical value
    EscapeEscapeEscape27Typical value
    BackspaceBackspaceBackspace8Typical value
    DeleteDeleteDelete46Typical value
    InsertInsertInsert45Typical value
    Arrow upArrowUpArrowUp38Typical value
    Arrow downArrowDownArrowDown40Typical value
    Arrow leftArrowLeftArrowLeft37Typical value
    Arrow rightArrowRightArrowRight39Typical value
    HomeHomeHome36Typical value
    EndEndEnd35Typical value
    Page UpPageUpPageUp33Typical value
    Page DownPageDownPageDown34Typical value
    Shift (left)ShiftShiftLeft16The right Shift has code ShiftRight and the same keyCode.
    Control (left)ControlControlLeft17Typical value
    Alt (left)AltAltLeft18Typical value
    Meta (left)MetaMetaLeft91The Windows or Command key. On Windows the right Windows key is 92 (code MetaRight); Firefox on macOS reports 224 for both Command keys.
    Caps LockCapsLockCapsLock20Typical value
    Context menuContextMenuContextMenu93Typical value
    F1F1F1112Typical value
    F12F12F12123Typical value
    Letter AaKeyA65event.key is “A” with Shift or Caps Lock; code and keyCode do not change.
    Digit 1 (top row)1Digit149Typical value
    Numpad 1 (Num Lock on)1Numpad197Same event.key as the top row; code, keyCode and location tell them apart.
    Slash/Slash191Typical value

    event.location values

    The DOM_KEY_LOCATION constants of KeyboardEvent.location in UI Events.
    ValueNameMeaning
    0StandardThe key has one copy on the keyboard (letters, digits, Enter, Space).
    1LeftThe left copy of a key that exists twice (Shift, Control, Alt, Meta).
    2RightThe right copy of a key that exists twice.
    3NumpadA key on the numeric keypad (including its Enter and the digits with Num Lock on).

    How to find a JavaScript key code

    1. Focus the capture box. Click the box or Tab to it. It says “Listening” while it has focus.
    2. Press a key. The result shows event.key, event.code, keyCode, which, location, modifiers and repeat. Hold Shift, Ctrl, Alt or Meta to see them reported.
    3. Copy the snippet. Choose the event.key or event.code line and copy it into your keydown handler. Use the keyCode line only for old code you cannot change.
    4. Leave the box. Press Tab to move on. To inspect Tab itself, turn on “Capture Tab and browser keys”; Escape or unticking the box releases it again.

    Frequently asked questions

    Is keyCode deprecated?
    Yes. keyCode, charCode and which are legacy properties: the UI Events specification keeps them only for compatibility with old content and does not define their values, and MDN marks them deprecated. Browsers still send them, so old code works, but new code should use event.key or event.code.
    What is the difference between event.key and event.code?
    event.key is the value the key produces, taking the keyboard layout, Shift and Caps Lock into account: “a”, “A”, “Enter”, “ArrowUp”. event.code names the physical key and ignores layout: pressing the key right of Tab on a French AZERTY keyboard gives key “a” but code “KeyQ”. Use key for text-like shortcuts and code for game controls such as WASD.
    What is the keyCode for Enter?
    13. Main Enter and numpad Enter both report keyCode 13 and event.key “Enter”; event.code is “Enter” for the main key and “NumpadEnter” for the keypad, and event.location is 0 and 3.
    How do I tell the left and right Shift apart?
    Use event.code (“ShiftLeft” or “ShiftRight”) or event.location (1 for left, 2 for right). event.key is “Shift” for both and keyCode is 16 for both.
    Why does a phone or tablet show keyCode 229 or “Unidentified”?
    On-screen keyboards and input method editors (IME) often compose text instead of sending one event per key, so browsers report keyCode 229 or event.key “Unidentified”. Listen to the input or beforeinput event for text instead of keydown.
    Why does pressing Tab leave the capture box?
    The box must not trap keyboard users, so by default Tab moves focus as usual after it is recorded. Turn on “Capture Tab and browser keys” to keep focus and inspect Tab; Escape (which is recorded first) or unticking the box releases the capture.
    Why are some shortcuts not reported?
    The browser or operating system handles some shortcuts, such as Ctrl+W, Ctrl+T, Alt+Tab or the Windows key, before the page sees them, and a page cannot receive them. Keys the page does receive appear here.
    Which keydown, keypress and keyup event should I use?
    Use keydown for shortcuts and keyup for “released” logic. keypress is deprecated and does not fire for many keys. This tool reads keydown, which fires for every key including modifiers and auto-repeats while the key is held (event.repeat is true).

    How it works

    The tool listens for keydown on the capture box and copies the fields of the KeyboardEvent: key, code, keyCode, which, location, the four modifier flags and repeat. Snippets are built from those values and quote them as JavaScript strings, appending a check for each modifier that was held. The result is whatever your browser, operating system and keyboard layout report, so the same physical key can give a different event.key on another layout. The table of common keys shows typical values on a US QWERTY keyboard: event.key and event.code names follow the W3C UI Events key and code specifications, while keyCode numbers are de facto legacy values, not defined by a specification. Auto-repeat events update the result but are not added to the history, which keeps the last eight keys. Nothing you press is stored or sent; analytics record only that the tool was used.

    Sources

    More: Web, URLs, images and networkAll developer toolsAll toolsHome & DIY calculators