Skip to content

useKeyPress ​

Listen for the keyboard press, support key combinations, and support alias.

Basic usage ​

Combination keys ​

Exact match ​

API ​

typescript
const state = useKeyPress(target?: Target);

Params ​

PropertyDescriptionType
keyFilterSupport keyCode、alias、combination keys、array、custom functionNumber | String | Number[]| String[] |(event: KeyboardEvent) => boolean
eventHandlerCallback function(event: KeyboardEvent) => void
optionadvanced optionsOptions

Options ​

PropertyDescriptionTypeDefault
eventsTrigger EventsEventListenerOrEventListenerObject-
targetDOM element or refHTMLElement | Document | Window-
exactMatchExact 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-

Source ​

Source · Document · Demo

Released under the MIT License.