1.0.4 • Published 3 years ago

hotkeys-nano v1.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

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()
1.0.4

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago