EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
hooks·hook·@astryxdesign/core

useHotkeys

Registers global keyboard shortcuts with a single window keydown listener per hook instance. Handlers live in a ref, so re-renders never re-subscribe. Skips events from typing targets (input, textarea, select, contenteditable) unless allowInInputs, skips defaultPrevented events, and calls preventDefault() on match. SSR-safe.

@astryxdesign/core/hooks

Signature

Call shape
useHotkeys(hotkeys: Hotkey[]): void
Parameters
NameType and behavior
hotkeysHotkey[] · required
Shortcut registrations. Each entry: { keys, onPress, allowInInputs?, isDisabled? }. keys is a "+"-separated combo like "mod+k", "shift+/", "escape"; "mod" is ⌘ on macOS and Ctrl elsewhere. onPress receives the KeyboardEvent after preventDefault(). allowInInputs (default false) lets the hotkey fire while typing in inputs/textareas/selects/contenteditable. isDisabled temporarily disables the entry.

Usage

Registers global keyboard shortcuts with a single window keydown listener per hook instance. Handlers live in a ref, so re-renders never re-subscribe. Skips events from typing targets (input, textarea, select, contenteditable) unless allowInInputs, skips defaultPrevented events, and calls preventDefault() on match. SSR-safe.

  • Use for app-level shortcuts like command palettes (mod+k), help overlays (shift+/), and navigation keys.
  • Pair with the Kbd component to display the same combo you register; both resolve "mod" per platform identically.
  • Use isDisabled to suspend shortcuts while a modal or wizard owns the keyboard, instead of unmounting the hook.
  • Use for focus-scoped keyboard navigation inside a widget; use useListFocus or useGridFocus instead.