isHotkeyPressed API
Function signature:
function isHotkeyPressed(key: string | string[], splitKey: string = ','): boolean
This function allows us to check if a specific key is pressed by the user.
const isHotkeyPressed = useIsHotkeyPressed();
const onClick = () => isHotkeyPressed('shift') ? setCount(count - 1) : setCount(count + 1);
Arguments
key
key: string | string[]
The key we want to listen to. This can be a string (like 'a', 'shift+a') or an array of strings (like ['a', 'shift+a']).
splitKey
key: string = ','
We can combine to check for multiple keys in one string by separating them with a comma (,). We can change
this by passing a different key.
Return value
boolean
The function returns true if the key or keystroke is currently pressed down, otherwise it will return false.