useKeyPress
Hook to detect if a specified key is pressed.
Usage
Live Editor
function App() { const isEnterPressed = useKeyPress("Enter"); return ( <div> <h1>Press the Enter key</h1> {isEnterPressed && <p>Enter key is pressed!</p>} </div> ); }
Result
Loading...
API
Parameter
key
:string
- The key to detect.
Returns : boolean
A boolean indicating if the specified key is pressed or not.