import { useEffect } from "react" ; function isInputEvent ( event ) { return ( event . target instanceof HTMLInputElement || event . target instanceof HTMLTextAreaElement || ( event . target instanceof HTMLSpanElement && Boolean ( event . target . contentEditable ) ) ) ; } export function useKeyPress ( callback , detectKeys , ignoreInputEvents = true ) { const handler = ( event ) => { if ( detectKeys . includes ( event . key ) && ! ( ignoreInputEvents && isInputEvent ( event ) ) && ! ( event . ctrlKey || event . metaKey || event . altKey ) ) { callback ( event ) ; } } ; useEffect ( ( ) => { window . addEventListener ( "keydown" , handler ) ; return ( ) => { window . removeEventListener ( "keydown" , handler ) ; } ; } , [ ignoreInputEvents , callback ] ) ; }