useKeyPressEvent ​
sensors
test coverage
Last changed: 24 days ago
Hook that listens for key press events on specified targets
typescript
import { useKeyPressEvent } from '@siberiacancode/reactuse';
Usage ​
typescript
useKeyPressEvent(ref, 'Enter', () => console.log('pressed'));
// or
const ref = useKeyPressEvent('Enter', (event) => console.log('pressed'));
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
key | UseKeyPressEventKey | - | The key or array of keys to listen for. |
target | HookTarget | Window | - | The target to attach the event listener to. |
listener | (event: KeyboardEvent) => void | - | The callback function to be executed when the specified key or keys are pressed. |
options? | UseKeyPressEventOptions | - | The options for the event listener. |
Returns
Parameters
Name | Type | Default | Note |
---|---|---|---|
key | UseKeyPressEventKey | - | The key or array of keys to listen for. |
listener | (event: KeyboardEvent) => void | - | The callback function to be executed when the specified key or keys are pressed. |
options? | UseKeyPressEventOptions | - | The options for the event listener. |