Skip to main content

useHotkey

Use useHotkey to implement hotkeys easily and enhance keyboard based control in your web apps.

import { Hotkey, useHotkey } from "react-better-hotkeys";

const Comp = () => {
useHotkey(Hotkey.Chord.Mod.K, () => {
console.log("CMD+K pressed!");
});
};

Arguments

keys

hotkey: HotKeyDefChordBase | HotKeyDefSequenceBase

The hotkey that is being listened on. Use the Hotkey object to create your hotkey.

callback

callback: HotkeyCallback

The function getting called if the defined hotkey was pressed.

options

options?: Partial<HotkeyOptions>

Optional options to shape the behaviour of the hotkey. More on HotkeyOptions

Examples

Basic usage

With options