{"version":3,"sources":["../src/hooks/useKeyPress.ts"],"names":["useKeyPress","targetKey","isPressed","setIsPressed","useState","useEffect","handleKeyDown","event","handleKeyUp"],"mappings":"wCAiCO,SAASA,CAAAA,CAAYC,CAA4B,CAAA,CACtD,GAAM,CAACC,CAAWC,CAAAA,CAAY,EAAIC,cAAS,CAAA,CAAA,CAAK,CAEhD,CAAA,OAAAC,eAAU,CAAA,IAAM,CACd,IAAMC,EAAiBC,CAAyB,EAAA,CAC1CA,CAAM,CAAA,GAAA,GAAQN,GAChBE,CAAa,CAAA,CAAA,CAAI,EAErB,CAAA,CAEMK,EAAeD,CAAyB,EAAA,CACxCA,CAAM,CAAA,GAAA,GAAQN,CAChBE,EAAAA,CAAAA,CAAa,CAAK,CAAA,EAEtB,EAEA,OAAO,MAAA,CAAA,gBAAA,CAAiB,SAAWG,CAAAA,CAAa,CAChD,CAAA,MAAA,CAAO,gBAAiB,CAAA,OAAA,CAASE,CAAW,CAErC,CAAA,IAAM,CACX,MAAA,CAAO,mBAAoB,CAAA,SAAA,CAAWF,CAAa,CAAA,CACnD,OAAO,mBAAoB,CAAA,OAAA,CAASE,CAAW,EACjD,CACF,CAAG,CAAA,CAACP,CAAS,CAAC,EAEPC,CACT","file":"useKeyPress.cjs","sourcesContent":["import { useEffect, useState } from \"react\";\n\n/**\n * Hook that detects when a specific key is pressed and held down.\n *\n * Tracks the current pressed state of a keyboard key, returning true while\n * the key is held down and false when released.\n *\n * @param targetKey - The key to detect (e.g., \"Enter\", \"Escape\", \"ArrowUp\", \"a\")\n *\n * @returns Boolean indicating if the target key is currently pressed\n *\n * @example\n * ```tsx\n * function GameControls() {\n *   const isSpacePressed = useKeyPress(' ');\n *   const isEnterPressed = useKeyPress('Enter');\n *   const isArrowUpPressed = useKeyPress('ArrowUp');\n *\n *   return (\n *     <div>\n *       <p>Space: {isSpacePressed ? 'Pressed' : 'Released'}</p>\n *       <p>Enter: {isEnterPressed ? 'Pressed' : 'Released'}</p>\n *       <p>Arrow Up: {isArrowUpPressed ? 'Pressed' : 'Released'}</p>\n *\n *       {isSpacePressed && <div>🚀 Boost active!</div>}\n *     </div>\n *   );\n * }\n * ```\n *\n * @see https://thibault.sh/hooks/use-key-press\n */\nexport function useKeyPress(targetKey: string): boolean {\n  const [isPressed, setIsPressed] = useState(false);\n\n  useEffect(() => {\n    const handleKeyDown = (event: KeyboardEvent) => {\n      if (event.key === targetKey) {\n        setIsPressed(true);\n      }\n    };\n\n    const handleKeyUp = (event: KeyboardEvent) => {\n      if (event.key === targetKey) {\n        setIsPressed(false);\n      }\n    };\n\n    window.addEventListener(\"keydown\", handleKeyDown);\n    window.addEventListener(\"keyup\", handleKeyUp);\n\n    return () => {\n      window.removeEventListener(\"keydown\", handleKeyDown);\n      window.removeEventListener(\"keyup\", handleKeyUp);\n    };\n  }, [targetKey]);\n\n  return isPressed;\n}\n"]}