Free JavaScript Keycode Finder

Press any key on your keyboard to see its JavaScript event properties.

Press any key…

Key History

No keys pressed yet

How It Works

  1. Press any key: Click in the input area and press any key on your keyboard, letters, numbers, function keys, arrows, modifiers, or special keys.
  2. Read the key codes: The tool instantly displays the key's event.key, event.code, event.keyCode (legacy), and charCode values.
  3. Use in your code: Copy the exact values you need for your keyboard event listeners or shortcut implementations.

Why Use Keycode Finder?

JavaScript keyboard events expose several different properties (key, code, keyCode, charCode, and which) and knowing which to use and what value to compare against is consistently tricky. The KeyCode Finder eliminates guesswork by letting you press a key and immediately see all its event properties. This is invaluable for building keyboard shortcuts, handling special keys, implementing hotkeys, and debugging keyboard event listeners.

Features

Frequently Asked Questions

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

event.key is the modern standard, it returns a readable string like "ArrowLeft" or "Enter". event.keyCode is a legacy numeric code (deprecated but still supported). Use event.key for new code; use event.keyCode when maintaining older browser compatibility.

How do I detect Ctrl+S or other key combinations?

Keyboard combinations use event.key combined with modifier checks: if (event.ctrlKey && event.key === "s"). Press Ctrl+S in this tool to see all the values, then replicate the exact condition in your event listener.

Why do some keys show the same keyCode?

keyCode values were not standardized and some keys share codes depending on context. event.code is more reliable, it identifies the physical key position (e.g., "KeyA") regardless of the keyboard layout, while event.key reflects what character that key produces.

A 30-year history of keyboard events in JavaScript

Keyboard events have a notoriously messy history in the DOM. Netscape Navigator 2 (1995) introduced the original onkeydown, onkeypress, and onkeyup handlers with a numeric keyCode property, which had no spec; browsers each invented their own values. Internet Explorer 4 (1997) implemented its own variant with event.keyCode as the only property, while Netscape stuck with event.which. DOM Level 2 Events (W3C, November 2000) standardised event flow (capture/bubble) but explicitly punted on keyboard events because vendors couldn't agree. The result: developers wrote code like e.keyCode || e.which for over a decade. DOM Level 3 Events (W3C Working Draft 2003, Recommendation 2018) finally introduced the modern event.key (Unicode character or named key like «ArrowLeft») and event.code (physical key position like «KeyA», independent of layout), along with deprecating keyCode, charCode, and which. The UI Events specification (W3C, ongoing) is the modern home for this work. Browsers caught up gradually: Chrome 51 (May 2016), Firefox 47 (June 2016), Safari 10.1 (March 2017) all shipped event.code support. The legacy keypress event is deprecated in favour of beforeinput and input events.

The 5 properties, decoded

Where keycode lookup actually matters

Common mistakes in keyboard event handling

More frequently asked questions

Why doesn't my key handler fire when the user has a non-US keyboard?

Almost always because you're checking event.key for a character that only exists with Shift on that layout. On a German QWERTZ keyboard, «/» is Shift+7 (not its own key); on AZERTY French, digits 0-9 are typed with Shift+the-row-above. Use event.code (physical key) for position-based shortcuts, or event.key for content-based shortcuts (where you actually want the character the user just typed).

How do I handle Cmd+K / Ctrl+K consistently across platforms?

The standard idiom: if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") { e.preventDefault(); openPalette(); }. On macOS, e.metaKey is the Cmd key; on Windows/Linux, e.ctrlKey is what users expect. Accept both. Always preventDefault because the browser binds Cmd+K to «focus address bar» in some browsers. Add !e.repeat to avoid firing on key-hold.

Can JavaScript detect global keystrokes outside the page?

No, and this is by design for security. The browser only fires keyboard events for the focused page or element. Browser extensions can listen with broader scope using the chrome.commands API. Native apps in Electron, Tauri, etc., can use OS-level global hooks. Banking and 2FA apps rely on this isolation: a malicious tab cannot keylog your password manager.

What's the right way to detect «just pressed» vs «being held»?

For toggles, check !e.repeat in the keydown handler, the first event has repeat: false, subsequent auto-repeat events have repeat: true. For continuous actions (game movement), track key state in a Set: add on keydown, remove on keyup, then in your render loop check keysHeld.has("KeyW"). This decouples input from frame rate and handles multiple simultaneous keys (move + jump).

Is anything sent to a server when I press keys here?

No. Key events are captured locally by JavaScript and displayed on this page without any network request. Open the Network tab in DevTools, type away; you'll see zero outbound traffic. Safe for testing in any context, including discovering what passwords or sensitive shortcuts produce on your keyboard.

Related Tools