A simple hotkey library.
npm install rx-hotkey
To bind or unbind hotkeys:
import {hotkey, createHotkey} from 'rx-hotkey'
// bind global hotkey
const unbind = hotkey('?', showHelp)
unbind()
// combo, with modifiers
hotkey('ctrl+r', (event) => {})
// sequences, space separated keys
hotkey('c i', (...events) => {})
hotkey('meta+k meta+v', (...events) => {})
// bind scoped hotkey
const scopedHotkey = createHotkey(sidebarElement)
const unbind = scopedHotkey('g h', goHome)
unbind()
To get or listen bindings:
import {hotkey, getKeyBindings, listenKeyBindings} from 'rx-hotkey'
hotkey('ctrl+r', (event) => {}, {meta: 1})
const scopedHotkey = createHotkey(sidebarElement, {scope: 'sidebar'})
const unbind = scopedHotkey('g h', goHome, {meta: 2})
getKeyBindings()
/* =>
Map {
"global" => Map {
"ctrl+r" => Object {meta: 1},
},
"sidebar" => Map {
"g h" => Object {meta: 2},
},
}
*/
// listen changes of key bindings
const unlisten = listenKeyBindings(handler)
unlisten()
- TimelineExample React Hooks example