正在加载,请稍候…

Keycode info

Identify JavaScript keyboard event properties for any key press. Shows keyCode, key, code, location, and modifier states (Shift, Ctrl, Alt, Meta). Essential for building keyboard shortcuts and accessibility features.

How to Use

  1. Step 1: Click anywhere on the page to focus the keyboard listener.
  2. Step 2: Press any key on your keyboard.
  3. Step 3: The key name, keyCode, code, location, and modifiers are displayed instantly.
  4. Step 4: Click the copy icon next to any field to copy that value.

Frequently Asked Questions

What is a keyCode?

The keyCode property is a legacy integer representing the key pressed. Modern code should use event.key or event.code instead.

What is the difference between key and code?

key represents the printed character. code represents the physical key position. Use key and code in modern JavaScript.

How should I listen for keyboard events in JavaScript?

Use event.key to get the logical value of the key pressed (e.g. 'a', 'Enter', 'ArrowUp'), and event.code for the physical key position (e.g. 'KeyA', 'ShiftLeft'). Avoid the deprecated keyCode property. For cross-platform shortcuts use event.code; for text input handling use event.key.

What is the difference between keyCode, which, and key in KeyboardEvent?

keyCode and which are deprecated — they return numbers (e.g., Enter=13) and are inconsistent for non-letter keys across keyboard layouts. key is the modern standard, returning meaningful strings (e.g., 'Enter', 'ArrowUp', 'a') independent of keyboard layout — use this. The code property returns the physical key position (e.g., 'KeyA') regardless of input language. New code should use event.key or event.code.