rx-hotkey
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

rx-hotkey

A simple hotkey library.

Coverage Status npm version minzipped size

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

Readme

Keywords

none

Package Sidebar

Install

npm i rx-hotkey

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

17.4 kB

Total Files

10

Last publish

Collaborators

  • ambarli