Keyboard Key Codes

Side-by-side event.key, event.code and legacy keyCode for common keys — quick reference for shortcuts and keyboard handlers.

Keyevent.keyevent.codekeyCode
A'a' / 'A''KeyA'65
Z'z' / 'Z''KeyZ'90
0'0''Digit0'48
1'1''Digit1'49
Enter'Enter''Enter'13
空格 Space' ''Space'32
Tab'Tab''Tab'9
Esc'Escape''Escape'27
Backspace'Backspace''Backspace'8
Delete'Delete''Delete'46
'ArrowLeft''ArrowLeft'37
'ArrowRight''ArrowRight'39
'ArrowUp''ArrowUp'38
'ArrowDown''ArrowDown'40
Shift'Shift''ShiftLeft' / 'ShiftRight'16
Ctrl'Control''ControlLeft' / 'ControlRight'17
Alt'Alt''AltLeft' / 'AltRight'18
F1'F1''F1'112
F12'F12''F12'123
/'/''Slash'191
.'.''Period'190
,',''Comma'188

Frequently Asked Questions

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

event.key is the "character value" (affected by Shift/caps, e.g. "a" or "A"); event.code is the physical "position" (always "KeyA", layout-independent). For shortcuts prefer event.code or event.key with modifier checks.

Why is keyCode deprecated?

KeyboardEvent.keyCode is a legacy IE-era numeric code inconsistent across layouts and deprecated by the Web standard. New code should use event.key / event.code, but legacy libraries still emit keyCode, so this table helps when maintaining old code.

How do I block browser default shortcuts (Ctrl+S, F12)?

Call event.preventDefault() on the keydown event for the target combination. Note: some shortcuts (e.g. F11 fullscreen, DevTools combos) are intercepted at the browser-process level and cannot be fully blocked by a page.

How do I detect combos like Ctrl+C / Ctrl+Enter?

In keydown, check both event.ctrlKey (metaKey on Mac) and event.key or event.code. Example Ctrl+C: event.ctrlKey && (event.key === "c" || event.code === "KeyC"). Prefer code to avoid IME/case issues.