import { MaybeRef } from '@react-hooks-library/shared' ; import { useCallback } from 'react' ; import { _window } from '../_ssr.config' ; import { useEventListener } from '../useEventListener' ; export type Keys = string | string [ ] ; export type KeyStrokeEventName = 'keydown' | 'keypress' | 'keyup' ; export type KeyStrokeOptions = { /** Key Stroke Event Name
     *
     * Can only be one of the following:
     *  - keydown
     *  - keypress
     *  - keyup
     */ eventName ? : KeyStrokeEventName ; default target ? : MaybeRef < EventTarget > ; default code ? : boolean ; default passive ? : false ; } ; param keys param handler param options see https export function useKeyStroke ( keys , handler , options = { } ) { const { target = _window , eventName = 'keydown' , passive = false , code = false } = options ; const listener = useCallback ( ( e ) => { const eventKey = code ? e . code : e . key ; keys . includes ( eventKey ) && handler ( e ) ; } , [ code , handler , keys ] ) ; return useEventListener ( target , eventName , listener , { passive } ) ; } param keys param handler param options see https export function useKeyDown ( keys , handler , options = { } ) { return useKeyStroke ( keys , handler , { ... options , eventName : 'keydown' } ) ; } param keys param handler param options see https export function useKeyPressed ( keys , handler , options = { } ) { return useKeyStroke ( keys , handler , { ... options , eventName : 'keypress' } ) ; } param keys param handler param options see https export function useKeyUp ( keys , handler , options = { } ) { return useKeyStroke ( keys , handler , { ... options , eventName : 'keyup' } ) ; }