useRecordHotkeys API
Function signature:
function useRecordHotkeys(
useKey?: boolean,
blacklist?: string[]
): [Set<string>, {
start: () => void,
stop: () => void,
resetKeys: () => void,
isRecording: boolean
}]
useKey
useKey: boolean // default: false
By default, the hook records key codes (physical keys). Pass true to record the produced character instead.
useKey: false— records"shift+1"when the user presses Shift+1useKey: true— records"!"when the user presses Shift+1 on a US layout
blacklist
blacklist: string[] // default: []
Array of key names to ignore while recording. Blacklisted keys retain their default behavior and are not added to the recorded set.
const [keys, { start, stop }] = useRecordHotkeys(false, ['tab', 'enter']);
Return value
const [keys, { start, stop, resetKeys, isRecording }] = useRecordHotkeys()
keys
keys: Set<string>
A Set of the keys that have been recorded. Each key appears only once. Use Array.from(keys) to convert it to an array.
start
start: () => void
Begins recording keystrokes.
stop
stop: () => void
Stops recording keystrokes.
resetKeys
resetKeys: () => void
Clears the recorded keys.
isRecording
isRecording: boolean
true while recording is active, false otherwise.