useKeyStroke

fires callback when a key is pressed

Demo

Usage

function useKeyStroke(key: KeyFilter, handler: (event: KeyboardEvent) => void, options?: KeyOptions): voiduseKeyStroke(true, (e: KeyboardEvente) => {
  // code goes here
})

Type Declaration

type KeyStrokeEventName = "keydown" | "keypress" | "keyup"

type KeyOptions = {
  eventName?: KeyStrokeEventName
  ref?: (() => EventTarget | null) | null
  passive?: boolean
  repeat?: boolean
}