Skip to content

useKeyboard ​

Category
Sensors

Hook that help to listen for keyboard events

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

Usage ​

typescript
useKeyboard({ onKeyDown: () => console.log('key down'), onKeyUp: () => console.log('key up') })

Demo ​

Api ​

Parameters

NameTypeDefaultNote
target?UseEventListenerTargetwindowThe target to attach the event listeners to
onKeyDown?(event: KeyboardEvent) => void-The callback function to be invoked on key down
onKeyUp?(event: KeyboardEvent) => void-The callback function to be invoked on key up

Contributors ​

Source • Demo