/** * Hook that detects when a specific key is pressed and held down. * * Tracks the current pressed state of a keyboard key, returning true while * the key is held down and false when released. * * @param targetKey - The key to detect (e.g., "Enter", "Escape", "ArrowUp", "a") * * @returns Boolean indicating if the target key is currently pressed * * @example * ```tsx * function GameControls() { * const isSpacePressed = useKeyPress(' '); * const isEnterPressed = useKeyPress('Enter'); * const isArrowUpPressed = useKeyPress('ArrowUp'); * * return ( *
Space: {isSpacePressed ? 'Pressed' : 'Released'}
*Enter: {isEnterPressed ? 'Pressed' : 'Released'}
*Arrow Up: {isArrowUpPressed ? 'Pressed' : 'Released'}
* * {isSpacePressed &&