use-hotkeys
Listen for keys combinations on document element
Import
Source
Docs
Package
Usage
use-hotkeys accepts as its first argument 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 pressedoptions
- object with extra options for hotkey handler
The second argument is a list of HTML tags:
tagsToIgnore
- HTML tag names that hotkeys will not trigger ontriggerOnContentEditable
- Whether shortcuts should trigger when based on contentEditable
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
:
With getHotkeyHandler
you can also add events to any dom node using .addEventListener
:
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