useKeyPress
Listen for the keyboard press, support key combinations, and support alias.
Basic usage
Combination keys
Exact match
API
const state = useKeyPress(target?: Target);
const state = useKeyPress(target?: Target);
Params
Property | Description | Type |
---|---|---|
keyFilter | Support keyCode、alias、combination keys、array、custom function | Number | String | Number[] | String[] |(event: KeyboardEvent) => boolean |
eventHandler | Callback function | (event: KeyboardEvent) => void |
option | advanced options | Options |
Options
Property | Description | Type | Default |
---|---|---|---|
events | Trigger Events | EventListenerOrEventListenerObject | - |
target | DOM element or ref | HTMLElement | Document | Window | - |
exactMatch | Exact match. If set true, the event will only be trigger when the keys match exactly. For example, pressing [shif + c] will not trigger [c] | Boolean | - |