Skip to content

useHotkeys

@astryxdesign/core v0.7.1 · useHotkeys

Usage ​

Registers global keyboard shortcuts with a single window keydown listener per hook instance. The shortcut list is read from a ref or getter, so updating it never re-subscribes. Skips events from typing targets (input, textarea, select, contenteditable) unless allowInInputs, skips defaultPrevented events, skips keys that belong to an IME composition, and calls preventDefault() on match. SSR-safe: the listener is only installed on mount.

ts
import { useHotkeys } from '@astryx-vue/core'

The listener is removed when the component unmounts, not when the list changes.

Best practices ​

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