Types
Core types
Section titled “Core types”Modifiers
Section titled “Modifiers”interface Modifiers { ctrl: boolean; shift: boolean; meta: boolean; alt: boolean;}SafeKey
Section titled “SafeKey”Keys that are safe to use across keyboard layouts: a–z and 0–9.
type SafeKey = "a" | "b" | ... | "z" | "0" | "1" | ... | "9";Shortcut
Section titled “Shortcut”A single chord: one non-modifier key plus zero or more modifiers.
interface Shortcut extends Modifiers { key: SafeKey;}ShortcutSequence
Section titled “ShortcutSequence”A sequence of one or more chords. "ctrl+k ctrl+c" parses to a sequence of length 2.
type ShortcutSequence = Shortcut[];ShortcutHandler
Section titled “ShortcutHandler”type ShortcutHandler = (event: KeyboardEvent) => void;Binding types
Section titled “Binding types”BindingOptions
Section titled “BindingOptions”Options passed to hk.add().
interface BindingOptions { scope?: string; // Only fires in this scope preventDefault?: boolean; // Default: true stopPropagation?: boolean; // Default: false enableInInput?: boolean; // Default: false requireReset?: boolean; // Default: false crossPlatform?: boolean; // Default: true layer?: string; // Default: "global"}Binding
Section titled “Binding”A resolved binding (returned by getBindings()).
interface Binding extends Omit<BindingOptions, "crossPlatform"> { readonly sequence: ShortcutSequence; readonly handler: ShortcutHandler;}Options types
Section titled “Options types”HotkeysOptions
Section titled “HotkeysOptions”Options for createHotkeys().
interface HotkeysOptions { target?: EventTarget; // Default: document scope?: string; // Default: "*" sequenceTimeout?: number; // Default: 1000 (ms)}Listener types
Section titled “Listener types”HeldKeysListener
Section titled “HeldKeysListener”type HeldKeysListener = (keys: ReadonlyArray<string>) => void;KeyHoldListener
Section titled “KeyHoldListener”Fires true when the key is the sole key held, false otherwise.
type KeyHoldListener = (held: boolean) => void;LayerChangeListener
Section titled “LayerChangeListener”type LayerChangeListener = (layers: ReadonlyArray<string>) => void;Recording types
Section titled “Recording types”RecordedShortcut
Section titled “RecordedShortcut”Returned by recordShortcut().
interface RecordedShortcut { key: string; // Raw key, lowercased ctrl: boolean; shift: boolean; meta: boolean; alt: boolean; mod: boolean; // Platform primary (Cmd on Mac, Ctrl elsewhere) mod2: boolean; // Platform secondary (Ctrl on Mac, Alt elsewhere) safe: boolean; // Whether the key is safe cross-layout unsafeReason?: string; // Explanation if unsafe}Devtools types
Section titled “Devtools types”DevtoolsEvent
Section titled “DevtoolsEvent”Discriminated union of all events emitted via the __devtools hook.
type DevtoolsEvent = | { type: "binding:fired"; shortcut: ShortcutSequence; layer: string; scope: string | undefined; event: KeyboardEvent; timestamp: number; } | { type: "binding:added"; shortcut: ShortcutSequence; options: BindingOptions; timestamp: number; } | { type: "binding:removed"; shortcut: ShortcutSequence; timestamp: number } | { type: "layer:change"; layers: readonly string[]; timestamp: number } | { type: "scope:change"; scope: string; previous: string; timestamp: number } | { type: "held-keys:change"; keys: readonly string[]; timestamp: number } | { type: "lifecycle"; action: "start" | "stop" | "destroy"; timestamp: number };DevtoolsHook
Section titled “DevtoolsHook”type DevtoolsHook = (event: DevtoolsEvent) => void;