hotkeys-nano
v1.0.4
Published
Simple lightweight JS keyboard hotkeys library
Downloads
4
Readme
hotkeys-nano
Simple lightweight JS keyboard hotkeys library
Installation
yarn add hotkeys-nano
or
npm install hotkeys-nano
Configure
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()