Skip to main content
Version: 5.0

isHotkeyPressed API

Function signature:

function isHotkeyPressed(key: string | string[], delimiter: string = ','): boolean

Check if a specific key or combination of keys is currently pressed.

import { isHotkeyPressed } from 'react-hotkeys-hook';

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

Arguments

key

key: string | string[]

The key or keys to check. This can be:

  • A single keycode string like 'a'
  • A delimited string of keycodes like 'shift,a'
  • An array of keycode strings like ['shift', 'a']

When multiple keys are provided, all of them must be pressed down for the function to return true.

mod is not supported

Use isHotkeyPressed(['ctrl', 'a']) or isHotkeyPressed(['meta', 'a']) instead of mod.

delimiter

delimiter: string // default: ","

The delimiter used to parse multiple keys from a single string.

Return value

boolean

Returns true if the key or key combination is currently pressed, otherwise false.