Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mytecor/hotkeys
Simple lightweight JS keyboard hotkeys library
https://github.com/mytecor/hotkeys
hotkeys shortcuts
Last synced: 4 days ago
JSON representation
Simple lightweight JS keyboard hotkeys library
- Host: GitHub
- URL: https://github.com/mytecor/hotkeys
- Owner: mytecor
- License: apache-2.0
- Created: 2018-12-10T17:25:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-10T23:13:37.000Z (about 4 years ago)
- Last Synced: 2024-12-08T23:48:23.187Z (15 days ago)
- Topics: hotkeys, shortcuts
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hotkeys-nano
Simple lightweight JS keyboard hotkeys library## Installation
```
yarn add hotkeys-nano
```
or
```
npm install hotkeys-nano
```### Configure
```js
Hotkeys.configure()
```
Look at the console## Usage
```js
import Hotkeys from 'hotkeys-nano'let hotkeys = new Hotkeys
hotkeys.set('ControlLeft+KeyS', e => {
e.preventDefault()
console.log('Saved')
})hotkeys.set('ControlLeft+ShiftLeft+KeyZ, ControlLeft+KeyY', e => {
console.log('Ctrl+Y')
})hotkeys.start()
```### Create hotkeys listener
```js
let hotkeys = new Hotkeys(target: Node)
```The Hotkeys object implements the standart js Map object
and it adds the following methods:### Start listening
```js
hotkeys.start()
```### Set new hotkey
```js
hotkeys.set(hotkeys: String|Array, callback: Function)
```
###### Example
```js
hotkeys.set('AltLeft+ArrowRight', e => {
console.log(e)
})
```### Delete hotkey
```js
hotkeys.delete(hotkeys: String|Array)
```
###### Example
```js
hotkeys.delete('AltLeft+ArrowRight')
```### Stop listening
```js
hotkeys.stop()
```