useKeyPressEvent ​
Hook that listens for key press events on specified targets
typescript
import { useKeyPressEvent } from '@siberiacancode/reactuse';
Usage ​
typescript
useKeyPressEvent('Enter', window, () => console.log('Enter key pressed'));
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
key | UseKeyPressEventKey | - | The key or array of keys to listen for. |
target | Window | - | The window object 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? | UseEventListenerOptions | - | The options for the event listener. |
Returns
Parameters
Name | Type | Default | Note |
---|---|---|---|
key | UseKeyPressEventKey | - | The key or array of keys to listen for. |
target | Document | - | The document object 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? | UseEventListenerOptions | - | The options for the event listener. |
Returns
Parameters
Name | Type | Default | Note |
---|---|---|---|
key | UseKeyPressEventKey | - | The key or array of keys to listen for. |
target | Target | - | The target element 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? | UseEventListenerOptions | - | 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? | UseEventListenerOptions | - | The options for the event listener. |