Skip to content

Keycode Info

Press any key to see its JavaScript keyCode, key, code, which, and location event properties.

Keycode Info tool

Loading...

Example

Input: Press the Enter key

Result: event.key: Enter, event.code: Enter, event.keyCode: 13, event.which: 13, event.location: Standard

key is the character or key name, code is the physical key position, and keyCode and which are the legacy numeric codes still used by older scripts.

  1. Open the tool page (on a phone or tablet, tap the input field to bring up the on-screen keyboard).
  2. Press any key to see its event properties.
  3. Read the key, code, keyCode, which and location values.
  4. Hold Ctrl, Shift, Alt or Meta while pressing another key to see the modifier states change.
  5. Copy the key value, or copy the keydown snippet for your event handler.

JavaScript Key Events: key, code and keyCode

Press any key and this tool shows what JavaScript sees. You get event.key, event.code, the older keyCode and which values, the key location, and whether Ctrl, Shift, Alt or Meta was held down. Press Enter, for example, and you get key "Enter", code "Enter" and keyCode 13.

The two modern properties answer different questions. event.key is the character or name the key produces, so it changes with the keyboard layout and with Shift. The same key can give "a", "A", or "q" on a French keyboard. event.code is the physical key position, such as KeyA or Digit1, and it stays the same whatever the layout. Use key for typed text, and code for game controls or shortcuts tied to a spot on the keyboard.

keyCode and which are older numeric codes. They are deprecated, which means browsers keep them only so old code still works. Their values can differ between browsers and layouts, so new code should avoid them. The location value tells left and right keys apart, like the two Shift keys, and marks keys on the number pad.

The tool also shows the event type, the repeat flag (true while a key is held down) and the character code of printable keys. It writes a keydown snippet for the key you pressed, with any modifiers, ready to copy. Arrow keys, the space bar and page keys are caught so the page does not scroll while you test.

On a phone or tablet, tap the input box to open the on-screen keyboard. Many mobile keyboards report key "Unidentified" and keyCode 229 while they build a word, which is normal. To look up the code point of any character, use Text to Unicode.

Sources

Frequently Asked Questions

Use event.key when you care about the character, such as text input or a shortcut that means "the letter S" on any layout. Use event.code when you care about the position, such as WASD game controls, which should stay in the same place on a French or German keyboard. Many apps check key for letters and code for game input.
Yes. keyCode and which are deprecated in favor of key and code. Browsers still support them so older sites keep working, and you will see them in plenty of existing code, such as keyCode 13 for Enter. For new code, use key or code, which are clearer and behave the same way across browsers and layouts.
keypress only fires for keys that produce a character, so Shift, Ctrl, the arrow keys and the function keys never trigger it. It is also deprecated. Listen for keydown instead, which fires for every key, and check event.key to find out which one was pressed. This tool listens for keydown.
In a keydown handler, check a modifier flag together with the key: event.ctrlKey && event.key === "s". On a Mac, users expect Command, which is event.metaKey. Call event.preventDefault() to stop the browser saving the page. Press the combination here and copy the snippet, which already includes the modifier checks.

Related Tools

Regex Tester

Test regular expressions with real-time match highlighting, group capture display, and a pattern library.

Developer Tools

HTML Entity Encode and Decode

Convert special characters to HTML entities and decode HTML entities back to readable text.

Developer Tools

Text to Unicode Converter

Convert text to Unicode code points and back. Supports U+XXXX, HTML hex, HTML decimal, and 0x hex formats.

Text and Writing

HTTP Status Codes Reference

Search and browse over 60 HTTP status codes grouped by class, each with its official name and a plain description.

Web and SEO Tools

Screen Resolution Detector

Detect your screen resolution, viewport size, pixel ratio, color depth, and display information.

Security and Encryption