Skip to content

useHotkeys ​

Category
Sensors

Hook that listens for hotkeys

typescript
import { useHotkeys } from '@siberiacancode/reactuse';

Usage ​

typescript
useHotkeys('control+a', () => console.log('hotkey pressed'));

Demo ​

Api ​

Parameters

NameTypeDefaultNote
hotkeysUseHotkeysHotkeys-The key or keys to listen for
callback(event: KeyboardEvent) => void-The callback function to be called when the hotkey is pressed
options.target?UseEventListenerTargetwindowThe target to attach the event listeners to
options.enabled?booleantrueEnable or disable the event listeners
options.preventDefault?booleantrueWhether to prevent the default behavior of the event
options.aliasMap?Record<string, string>-Alias map for hotkeys

Contributors ​

Source • Demo