import { useState , useEffect } from 'react' ; export default function useMultiKeyPress ( ) { const [ keysPressed , setKeyPressed ] = useState < Set < string > > ( new Set ( ) ) ; const keydownHandler = ( e ) => { setKeyPressed ( ( prev ) => new Set ( prev . add ( e . code ) ) ) ; } ; const keyupHandler = ( e ) => { if ( navigator . platform . includes ( 'Mac' ) && e . code . includes ( 'Meta' ) ) { keysPressed . clear ( ) ; setKeyPressed ( new Set ( ) ) ; return ; } keysPressed . delete ( e . code ) ; setKeyPressed ( new Set ( keysPressed ) ) ; } ; useEffect ( ( ) => { window . addEventListener ( 'keydown' , keydownHandler ) ; window . addEventListener ( 'keyup' , keyupHandler ) ; return ( ) => { window . removeEventListener ( 'keydown' , keydownHandler ) ; window . removeEventListener ( 'keyup' , keyupHandler ) ; } ; } , [ ] ) ; return keysPressed ; }