1.0.4 • Published 5 years ago
hotkeys-nano v1.0.4
hotkeys-nano
Simple lightweight JS keyboard hotkeys library
Installation
yarn add hotkeys-nanoor
npm install hotkeys-nanoConfigure
Hotkeys.configure()Look at the console
Usage
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
let hotkeys = new Hotkeys(target: Node)The Hotkeys object implements the standart js Map object and it adds the following methods:
Start listening
hotkeys.start()Set new hotkey
hotkeys.set(hotkeys: String|Array, callback: Function)Example
hotkeys.set('AltLeft+ArrowRight', e => {
console.log(e)
})Delete hotkey
hotkeys.delete(hotkeys: String|Array)Example
hotkeys.delete('AltLeft+ArrowRight')Stop listening
hotkeys.stop()