keys/api/hotkey-format
Hotkey format
Modifier syntax, key aliases, and matching rules for @diffgazer/keys hotkey strings.
Hotkeys are strings like "mod+k", "shift+Enter", or "ArrowDown". Each string is parsed once when the handler registers, then matched against keyboard events at dispatch time, and used with useKey.
Modifiers
Joined with +. The last segment is the key, everything before it is a modifier.
Key aliases
Special rules
- Uppercase single letter implies Shift:
"G"is equivalent to"shift+g". - Case-insensitive: both the hotkey string and
event.keyare lowercased before comparison. - Strict modifier matching: all four modifier keys (
ctrl,shift,alt,meta) must match exactly. PressingCtrl+Shift+Kwill not match"mod+k"— it would match"mod+shift+k". - Platform detection:
modresolves vianavigator.userAgent(cached after first check).
Shifted punctuation aliases
The + delimiter makes shifted punctuation like ? or + ambiguous. Use named aliases.
Strict modifier matching still applies: if a punctuation key requires Shift on the user's layout, include shift+ in the hotkey.
Examples
tsx