JavaScript Keycode Finder

Press any key to see its event.key, event.code and keyCode values, with a ready snippet.

JavaScript Keycode Finder tool

Press a key

event.key, event.code and keyCode appear below.

Click or tap here, then press any key.

event.key-
event.code-
event.keyCode-
event.which-
event.location-
Modifier keys-
Unicode-
event.repeat-
JavaScript snippet
document.addEventListener('keydown', function (event) {
  if (event.key === 'Enter') {
    // your code here
  }
});
Recent keys
    Reference: common keys
    event.keyevent.codekeyCode
    BackspaceBackspace8
    TabTab9
    EnterEnter or NumpadEnter13
    ShiftShiftLeft or ShiftRight16
    ControlControlLeft or ControlRight17
    AltAltLeft or AltRight18
    PausePause19
    CapsLockCapsLock20
    EscapeEscape27
    ' ' (space)Space32
    PageUpPageUp33
    PageDownPageDown34
    EndEnd35
    HomeHome36
    ArrowLeftArrowLeft37
    ArrowUpArrowUp38
    ArrowRightArrowRight39
    ArrowDownArrowDown40
    InsertInsert45
    DeleteDelete46
    0 to 9Digit0 to Digit948 to 57
    a to z (A to Z with Shift)KeyA to KeyZ65 to 90
    Meta (Windows or Command)MetaLeft or MetaRight91, 92 or 93
    ContextMenuContextMenu93
    0 to 9 on the keypadNumpad0 to Numpad996 to 105
    *NumpadMultiply106
    +NumpadAdd107
    - on the keypadNumpadSubtract109
    . on the keypadNumpadDecimal110
    / on the keypadNumpadDivide111
    F1 to F12F1 to F12112 to 123
    NumLockNumLock144
    ScrollLockScrollLock145
    ;Semicolon186
    =Equal187
    ,Comma188
    -Minus189
    .Period190
    /Slash191
    `Backquote192
    [BracketLeft219
    \Backslash220
    ]BracketRight221
    'Quote222

    keyCode values are those of Chrome, Edge and Safari on a US layout. Firefox reports 59, 61 and 173 for the semicolon, equals and minus keys.

    About the JavaScript Keycode Finder

    Writing keyboard shortcuts or game controls means knowing exactly what the browser reports for each key, and the answer differs between keyboard layouts. This keycode finder captures any key or combination and shows event.key, event.code, the older keyCode and which values, the key location and the state of Shift, Ctrl, Alt, Meta and Caps Lock, with a snippet to paste into your code. Modern code should usually rely on event.key or event.code rather than keyCode.

    Modern code should use event.key, the character or name of the key such as a, A, Enter or ArrowLeft, which follows the keyboard layout, or event.code, the physical key position such as KeyA or Digit1, which is ideal for game controls because it stays the same on QWERTY, AZERTY and other layouts. The numeric keyCode is deprecated but still shown, because older code and libraries rely on it.

    A ready-to-copy snippet shows how to test for the key you pressed, including any modifier keys, and a short history lists your recent keys so you can compare them. The reference table covers common keys with their key, code and keyCode values. Some shortcuts, such as Ctrl+W or Cmd+Q, are reserved by the browser or the operating system and never reach a web page.

    Everything runs locally and no keystrokes are sent or stored. For other browser details, try the user agent parser, and to look up character codes, the ASCII table or the Unicode converter.

    How to use the JavaScript Keycode Finder

    1. Focus the capture areaClick or tap the box so that it receives your key presses.
    2. Press a keyPress any key or combination, such as Shift+A or Ctrl+Enter.
    3. Read the valuesSee event.key, event.code, keyCode, location and modifiers.
    4. Copy the snippetCopy the ready code to handle that key in your script.

    JavaScript Keycode Finder features

    • event.key and event.code
    • Legacy keyCode and which
    • Key location: left, right or keypad
    • Shift, Ctrl, Alt, Meta and Caps Lock state
    • Auto-repeat detection
    • Copyable JavaScript snippet
    • History of recent keys
    • Reference table of common keys

    Common uses

    • Writing keyboard shortcuts for a web app
    • Setting up game controls by physical key
    • Debugging keyboard handling on different layouts
    • Migrating old keyCode checks to event.key
    • Teaching DOM keyboard events

    Keyboard events in practice: app shortcuts, Mac and Windows keys, not hijacking typing, Urdu layouts, IMEs, phones and games

    By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

    Keyboard handling looks simple until real users arrive with different operating systems, keyboard layouts and phones. This guide builds a set of shortcuts for a web app and then covers the details that break them: Mac and Windows modifier keys, shortcuts firing while people type, Urdu keyboard layouts, input method editors, virtual keyboards on phones, accessibility rules and key handling in games.

    A worked example: shortcuts for a web app

    A web app wants three shortcuts: slash to focus the search box, Escape to close an open dialog and Ctrl+K, or Cmd+K on a Mac, to open a command menu. Pressing each in the keycode finder shows the values to test. The command menu check is written as (e.ctrlKey || e.metaKey) && e.key === 'k', covering both platforms, and calling e.preventDefault() stops the browser's own action for that combination where the browser allows it.

    Mac and Windows

    Mac users expect Cmd where Windows and Linux users expect Ctrl. Checking metaKey alongside ctrlKey covers both, and showing the right symbol in tooltips, ⌘K on Macs and Ctrl+K elsewhere, makes shortcuts discoverable. Avoid combinations the operating system reserves, which never reach the page.

    Do not hijack typing

    A slash shortcut must not trigger while someone types a slash in a form field. Before handling a shortcut, check where the key was pressed and ignore it when the target is an input, a text area or an editable element, for example with e.target.closest('input, textarea, [contenteditable]'). Escape is often allowed through, so people can leave a field quickly.

    Urdu keyboard layouts

    With an Urdu layout active, pressing the key labelled A may produce an Urdu letter, so event.key reports that letter, not a. A shortcut checking e.key === 'k' then never fires for Urdu typists. Checking event.code, which reports the physical key such as KeyK whatever the layout, keeps letter shortcuts working. Test with each layout your users are likely to have.

    Input method editors

    People typing in languages that use input method editors compose characters over several key presses. During composition, keydown events report isComposing as true, and pressing Enter confirms the composition rather than submitting a message. Chat and search boxes should ignore Enter while e.isComposing is true, or they will send half-typed text.

    Phones and virtual keyboards

    On Android, many virtual keyboards report keydown events with the key Unidentified and keyCode 229, because the keyboard sends text rather than individual key presses. For reacting to typed text on phones, the input and beforeinput events are reliable where keydown is not. Reserve keydown for physical keyboards and special keys.

    Accessibility rules

    Single-character shortcuts without a modifier, such as pressing s to save, can be triggered accidentally by speech input users and people with tremors. Accessibility guidance requires that such shortcuts can be turned off, remapped or work only when a particular element has focus. Listing all shortcuts on a help screen, often opened with a question mark, helps everyone.

    Keys in games

    Games should use event.code so WASD movement stays in the same physical place on every layout. Track pressed keys in a set, adding on keydown and removing on keyup, and clear the set when the window loses focus, because keyup never arrives for keys released while another window is active. Ignore events where e.repeat is true for one-off actions such as jumping.

    Common mistakes

    • Checking only ctrlKey and forgetting Mac users.
    • Triggering shortcuts while people type in fields.
    • Using event.key for letter shortcuts used with several layouts.
    • Submitting text while an input method is composing.

    Related tools

    To try handlers quickly, use Live HTML Editor. To look up character codes, try Text to ASCII Converter, and to check physical keys on your keyboard, Keyboard Tester.

    Differences between browsers

    Older keyCode values are not identical across browsers for every key. The minus key, for example, has historically reported 173 in Firefox and 189 in Chrome. Code that must support old keyCode logic should test in each browser, while new code using event.key or event.code avoids these inconsistencies entirely.

    Dead keys and accents

    On many international layouts, pressing an accent key reports the key value Dead and produces nothing until the next key is pressed, when the combined character appears. Shortcuts should never rely on these keys. Testing your shortcuts with a few common layouts reveals any that depend on keys some users cannot press directly.

    Documenting shortcuts

    Show shortcuts beside menu items and in button tooltips, so users discover them naturally. Follow platform conventions, such as Ctrl or Cmd with S to save, and avoid overriding well-known browser shortcuts such as Ctrl+F unless your app offers a clearly better search. Surprising users by changing familiar behaviour quickly erodes trust.

    Releasing keys reliably

    Some actions depend on a key being held, such as push-to-talk in a voice chat or showing a preview while a key is down. Listen for keyup as well as keydown, and also reset the state when the page is hidden or loses focus, otherwise the action can stay stuck on after the user switches tabs.

    Privacy

    Key events are read and displayed in your browser. Nothing you type is recorded, sent or stored.

    Frequently asked questions

    What is the difference between event.key and event.code?

    event.key is the value the key produces, taking the keyboard layout and Shift into account, such as a or A. event.code identifies the physical key, such as KeyA, which stays the same whatever the layout or modifiers.

    Is keyCode deprecated?

    Yes. keyCode and which are deprecated in the DOM standard, and their values differ between browsers and layouts for some keys. They still work in all browsers, but new code should use event.key or event.code instead.

    What is the keyCode for Enter?

    Enter has keyCode 13, event.key Enter and event.code Enter, or NumpadEnter on the numeric keypad. Other common codes are 27 for Escape, 32 for Space, 9 for Tab and 37 to 40 for the arrow keys.

    Why can't I capture some shortcuts?

    Browsers and operating systems reserve some combinations, such as Ctrl+W, Ctrl+T, Ctrl+N, Alt+F4 and Cmd+Q, so pages never receive them. Most other keys, including F5 and Ctrl+S, reach the page, and this tool blocks their normal action only while the capture area has focus.

    What does event.location mean?

    It tells which of several identical keys was pressed: 0 for a standard key, 1 for the left Shift, Ctrl, Alt or Meta key, 2 for the right one, and 3 for keys on the numeric keypad.

    Does it work on phones and tablets?

    Partly. On-screen keyboards often report the key as Unidentified with keyCode 229 while text is being composed, because they work through text input rather than physical keys. Use the typing box for them; a hardware keyboard works normally.

    Are my keystrokes recorded?

    No. The values are only displayed in this page and kept in the short history on your screen. Nothing is sent to a server or saved, and the history disappears when you close or reload the page.