b2KIT

JavaScript Keycode / Event Tester

Press any key to see its keyCode, key, code, and which values with event properties for development reference.

Tested tool guide Tested browser tools Checked August 16, 2026

What JavaScript Keycode / Event Tester does, with a checked example

Keyboard presses are not represented by one universal identifier. This tester captures a key press in its page and displays the event's key, code, keyCode, and which values for direct comparison. key describes the interpreted key value, while code identifies a physical-key designation such as KeyA or Enter. The common surprise is that these fields are not interchangeable: keyboard layout and modifiers can change key, while keyCode and which are deprecated legacy numbers that can vary by browser or event circumstances.

Worked example

A concrete input and expected output from the current implementation.

Input

Press the main Enter/Return key once with no modifier keys held. Do not use the numeric-keypad Enter key.

Expected output

key: Enter; code: Enter; keyCode: 13; which: 13

The main Enter key has Enter as both its logical key value and its physical-key code. The legacy keyCode and which values for this key event are both 13.

How the result is produced

1

Capture a key press

Give the page focus, then press one key. The tester updates its display with properties from the keyboard event delivered to the page. The result represents an event, not a pasted text string. Modifier state and the active keyboard layout can therefore affect the value reported by key even when the same physical key is pressed.

2

Compare the identifiers

Read key when the produced meaning matters, and read code when the physical key position matters. Inspect keyCode and which when diagnosing older JavaScript that expects numeric identifiers. Those legacy fields are not substitutes for key or code, even when they happen to contain the same number in a simple test such as Enter.

Good uses

  • Checking which event.code a laptop, external keyboard, or unusual key reports before assigning a game or editor binding.
  • Comparing event.key with event.code while holding Shift, Alt, Control, or Meta to debug a browser keyboard shortcut.
  • Reproducing a legacy handler's keyCode or which condition before replacing its numeric test with key or code.

Limits and checks

  • The result describes the event delivered by the current browser, operating system, keyboard layout, and hardware. It is not a universal lookup table for every user's keyboard.
  • keyCode and which are deprecated. A matching number confirms what this event reported, not that the number is appropriate for new keyboard handling.
  • Some browser or operating-system shortcuts may be intercepted before the page receives them. Input methods, dead keys, media keys, and composition can also produce less familiar values.

Common questions

Why are key and code different when I press the same labeled key?

key reflects the value the browser interprets after keyboard layout and modifiers are considered. code identifies the key's standardized physical designation, such as KeyQ, without expressing the character produced by the active layout. They can therefore differ on non-US layouts, and Shift can change key without changing code. Choose according to whether meaning or physical position matters.

Can I copy one result into a shortcut handler and expect it to work everywhere?

No. A simple key such as Enter is broadly consistent, but printable keys, modifier combinations, alternate layouts, input methods, and browser or operating-system shortcuts complicate portability. Test the environments you support. Prefer key for a logical value and code for a physical position; avoid basing new handling on keyCode or which.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools