Skip to main content
Version: 3.x

useIsHotkeyPressed API

This hook is deprecated

Please do not use this hook anymore since it will be removed in version 4. Instead please use the more direct approach by importing the isHotkeyPressed function.

Function signature:

function useIsHotkeyPressed(): (key: string | number) => boolean

This hook allows us to check on function execution if a specific key is pressed by the user. If a user presses a button we might want to check if a key is pressed down to execute an alternative action for that button.

const isHotkeyPressed = useIsHotkeyPressed();

const onClick = () => isHotkeyPressed('shift') ? setCount(count - 1) : setCount(count + 1);