rx-hotkey
v1.0.0
Published
A simple hotkey library
Downloads
24
Readme
rx-hotkey
A simple hotkey library.
Install
npm install rx-hotkey
Usage
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()
Examples
- TimelineExample React Hooks example