useKeyPress

Events

A React hook that detects when a specific key is pressed and held down, returning true while pressed and false when released.

Installation

npm install @thibault.sh/hooks

API Reference

Signature

function useKeyPress(targetKey: string): boolean

Parameters

NameTypeDescriptionDefault
targetKey
string
The key to detect (e.g., 'Enter', 'Escape', 'ArrowUp', 'a').-

Returns

boolean

Boolean indicating if the target key is currently pressed.

useKeyPress Hook - React Key Press Detection