Primitives / foldkit-primitives/events

matchHotkey

function · packages/primitives/src/events/hotkeys.ts:165

function matchHotkey(
  pattern: string,
  press: KeyPress,
  options?: HotkeyOptions,
): boolean

Hotkey matching as a pure function over a Pressed payload: matchHotkey answers whether a press is the shortcut, so update stays a table of chords instead of a nest of modifier checks. Patterns read like "ctrl+shift+k": modifiers first (any order), the key last, case-insensitive, with cmd/command and option as the Mac names for meta and alt, and mod for Meta on a Mac (platform: 'mac' or 'ios') and Control elsewhere. Matching is exact: unlisted modifiers must be up. Auto-repeat never matches, so holding a chord fires once. A letter or digit also matches by its physical code when the layout typed another character (Option+N on a Mac types a tilde), but never when it typed a different Latin letter, so a Dvorak k is not a KeyK. A press made while typing in a field (typing) does not match unless the pattern holds Control, Alt or Meta, or allowInInput is set. space (or a bare space) means the space key; esc means escape. A pattern with no key, or two keys, matches nothing: predicates return false, they do not throw on the hot path.