useHotkey
Keyboard shortcuts with platform-aware mod keys.
Runs a callback for a combination such as 'mod+k' (Command+K on macOS, Control+K elsewhere), 'shift+?' or 'escape'. Skips plain keys while the reader types in a field, and returns aria-keyshortcuts and Kbd keys for the hint.
Usage
Examples
Platform-aware mod key
Single-key shortcuts that can be turned off
API
7 options
2 return values
Accessibility
Every shortcut needs a visible control that does the same thing. Put aria-keyshortcuts on that control and show the keys with Kbd. Avoid single-key shortcuts unless they can be turned off (WCAG 2.1.4).
Notes
parseHotkey,matchHotkey,toAriaKeyShortcutsandtoKbdKeysare exported for custom handling.
Related
KbdKbd renders keyboard keys and multi-key shortcuts.2 examplesuseCopyToClipboardCopy text with a temporary copied state and a fallback.useEventListenerDeclarative DOM event listener with cleanup.useHoverPointer hover state with props to spread, ignoring touch.useMousePositionTrack viewport, page and optional element-relative pointer coordinates.useOnClickOutsideRun a callback when a press lands outside one or more elements.