Home/Developer, Code & Web Engineering Tools/Keycode & Keyboard Event Inspector

Keycode & Keyboard Event Inspector

Inspect JavaScript KeyboardEvent attributes in real-time including event.key, event.code, which, location, and generate ready-to-use event handler snippets.

Live Key Listener

Listening Globally
Press Any Key on Your Keyboard
Enter
event.code: Enter
Click anywhere or focus this box to capture keyboard events in real-time
event.key
Enter
W3C Standard
event.code
Enter
Physical Key
event.keyCode
13
Deprecated
event.which
13
Deprecated
ShiftFALSE
ControlFALSE
Alt / OptionFALSE
Meta / CmdFALSE
LocationStandard (0)
RepeatNo
IME ComposingNone

Code Generation & Payloads

// Modern W3C Standard Keyboard Handler
window.addEventListener('keydown', (event) => {
  if (event.key === "Enter") {
    console.log('Key captured:', event.key);
    // Code identifier: "Enter"
    // event.preventDefault();
  }
});
No keys pressed yet. Type on your keyboard to record event stream.

Understanding JavaScript Keyboard Events: event.key vs. event.code

In modern web development, capturing keyboard input accurately is critical for building accessibility-compliant shortcuts, interactive canvas games, and rich text editors. Prior to the modern DOM Level 3 Events specification, developers relied heavily on numeric properties such as event.keyCode and event.which. However, these legacy values produced severe bugs across international keyboards and different operating systems.

Modern Standard: event.key

event.key returns the semantic value of the character generated. It accounts for whether the Shift key is held down (producing "A" instead of "a") and adapts to localized keyboard layouts (e.g., QWERTY, AZERTY, or Cyrillic).

if (event.key === 'Enter' || event.key === 'Escape') { submit(); }

Physical Hardware: event.code

event.code identifies the physical hardware key on the keyboard, completely unaffected by language layout or modifier keys. Pressing the physical 'W' key always emits "KeyW", making it the ideal choice for WASD game controls.

if (event.code === 'KeyW') { player.moveForward(); }

KeyboardEvent Property Comparison & Deprecation Matrix

The W3C DOM Level 3 Event standard explicitly discourages legacy numeric codes in favor of string-based identifiers. Review the feature comparison below:

PropertyTypeSpecification StatusPrimary Use Case
event.keystringStandard (Recommended)Form inputs, keyboard shortcuts, UI navigation
event.codestringStandard (Recommended)Game movement (WASD), physical key bindings
event.locationnumber (0-3)StandardDistinguishing Left vs. Right Shift / Numpad
event.keyCodenumberDeprecated (Legacy)Legacy browser maintenance (IE11 and older)
event.whichnumberDeprecated (Legacy)Older jQuery compatibility layers

Common JavaScript Keycode Reference Table

Quick reference values for the most frequently implemented keyboard keys across standard web applications:

Enter / Return
key: "Enter"code: Enter
keyCode: 13
Escape
key: "Escape"code: Escape
keyCode: 27
Spacebar
key: " "code: Space
keyCode: 32
Tab
key: "Tab"code: Tab
keyCode: 9
Backspace
key: "Backspace"code: Backspace
keyCode: 8
Delete
key: "Delete"code: Delete
keyCode: 46
Arrow Up
key: "ArrowUp"code: ArrowUp
keyCode: 38
Arrow Down
key: "ArrowDown"code: ArrowDown
keyCode: 40
Arrow Left
key: "ArrowLeft"code: ArrowLeft
keyCode: 37
Arrow Right
key: "ArrowRight"code: ArrowRight
keyCode: 39
Left Shift
key: "Shift"code: ShiftLeft
keyCode: 16
Left Control
key: "Control"code: ControlLeft
keyCode: 17

Frequently Asked Questions (FAQ)

Why is event.keyCode deprecated in modern JavaScript?

The W3C deprecated event.keyCode and event.which because they are inconsistent across international keyboard layouts, operating systems, and browsers. Modern standards recommend event.key for semantic character values and event.code for physical key positions.

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

event.key returns the actual semantic character generated taking Shift, AltGr, and active keyboard language layouts into account (e.g., "a", "A", "Å"). In contrast, event.code represents the physical hardware key on the keyboard independent of layout (e.g., "KeyA", "Digit1").

How does KeyboardEvent.location identify key positions?

KeyboardEvent.location indicates whether the pressed key was on the standard section (0), left side (1, e.g., Left Shift), right side (2, e.g., Right Shift), or numeric keypad (3, e.g., Numpad 5).

How can I prevent default browser keyboard behaviors like scrolling?

Call event.preventDefault() inside a keydown event listener. This prevents native browser behaviors like Space or Arrow keys scrolling the viewport, Tab moving focus, or Backspace navigating back in older browsers.

Does this tool track modifier keys like Shift, Control, Alt, and Meta?

Yes. The inspector displays boolean status flags for event.shiftKey, event.ctrlKey, event.altKey, and event.metaKey (Command on macOS or Windows key on PC), as well as repeat and isComposing flags for IME inputs.

Found this tool helpful? Share it with others!

Share on Facebook
Share on X
Share on LinkedIn
Copy URL

Related & Complementary Utilities

Explore more privacy-first client-side web tools.