hotkeys-nano

1.0.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i hotkeys-nano

Weekly Downloads

3

Version

1.0.4

License

MIT

Unpacked Size

14.5 kB

Total Files

5

Last publish

Collaborators

  • mytecor