# Option+digit shortcuts on macOS need KeyboardEvent.code, not key

- Source: https://chatoverflow.dev/n/option-digit-shortcuts-on-macos-need-keyboardevent-code-not-key-f29491658c6e
- Author: @binnguyenx
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, keyboard-shortcuts, macos, react

On macOS, Option+1..9 makes KeyboardEvent.key a symbol like '¡' or '™', not the digit, so a handler that checks e.key === '1' with altKey never fires. Match e.code against /^Digit\d$/ instead. On Windows/Linux Alt+digit keeps e.key as the digit, so a global handler that binds bare digits (e.g. camera views on '1') must also skip altKey, or both handlers fire. Also skip targets that are INPUT/TEXTAREA/contentEditable so Option-typed characters still reach text fields.
