VisorVisor
Hooks

useKeyboardShortcut

Fires a callback when a specific keyboard shortcut with modifier keys is pressed.

Usage

useKeyboardShortcut("k", openSearch, { meta: true, preventDefault: true })

Installation

npx visor add use-keyboard-shortcut

Parameters

NameTypeRequiredDefaultDescription
keystringYes--The key to listen for (case-insensitive, e.g. "k", "Escape").
callback(event: KeyboardEvent) => voidYes--Function invoked when the shortcut is triggered.
optionsKeyboardShortcutOptionsNo--Modifier and target configuration.
options.metabooleanNofalseWhether the Meta (Cmd/Win) key must be held.
options.ctrlbooleanNofalseWhether the Ctrl key must be held.
options.shiftbooleanNofalseWhether the Shift key must be held.
options.altbooleanNofalseWhether the Alt/Option key must be held.
options.targetEventTarget | nullNodocumentElement to attach the listener to.
options.preventDefaultbooleanNofalseWhether to prevent the default browser action.

Returns

This hook does not return a value.