use-hotkeys
Listen for keys combinations on document element
Import
Source
Docs
Package
Usage
use-hotkeys accepts an array of hotkeys and handler tuples:
hotkey
- hotkey string e.g.ctrl+E
,shift+alt+L
,mod+S
handler
- event handler called when given combination was pressed
Targeting elements
use-hotkeys hook can work only with document element, you will need to create your own event listener
if you need to support other elements. For this purpose package exports getHotkeyHandler
function
which should be used with onKeyDown
:
Supported formats
mod+S
– detects⌘+S
on macOS andCtrl+S
on Windowsctrl+shift+X
– handles multiple modifiersalt + shift + L
– you can use whitespace inside hotkeyArrowLeft
– you can use special keys using this format