Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ambar/rx-hotkey
Live Demo: https://ambar.li/rx-hotkey/
https://github.com/ambar/rx-hotkey
dom hotkey keyboard shortcut
Last synced: about 1 month ago
JSON representation
Live Demo: https://ambar.li/rx-hotkey/
- Host: GitHub
- URL: https://github.com/ambar/rx-hotkey
- Owner: ambar
- License: mit
- Created: 2019-02-08T13:18:22.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T04:15:24.000Z (about 2 years ago)
- Last Synced: 2024-04-08T16:13:30.358Z (10 months ago)
- Topics: dom, hotkey, keyboard, shortcut
- Language: TypeScript
- Homepage:
- Size: 3.63 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rx-hotkey
> A simple hotkey library.
[![Coverage Status](https://coveralls.io/repos/github/ambar/rx-hotkey/badge.svg?branch=master)](https://coveralls.io/github/ambar/rx-hotkey?branch=master)
[![npm version](https://badgen.net/npm/v/rx-hotkey)](https://www.npmjs.com/package/rx-hotkey)
[![minzipped size](https://badgen.net/bundlephobia/minzip/rx-hotkey)](https://bundlephobia.com/result?p=rx-hotkey)## Install
```bash
npm install rx-hotkey
```## Usage
To bind or unbind hotkeys:
```js
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:
```js
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](https://ambar.li/rx-hotkey/) React Hooks example