dherault / piano-keys

A JavaScript shorcuts and hotkeys librairy

Home Page:https://dherault.github.io/piano-keys/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Piano keys

npm version PRs Welcome

A JavaScript hotkeys librairy in less than 3KB.

Checkout the demo!

Installation

npm install piano-keys --save

Usage

import hotkeys from 'piano-keys'

const element = document.getElementById('hello')

hotkeys(element, 'ctrl+b', () => console.log('bold'))
hotkeys(element, 'cmd+k a', () => console.log('super settings'))
hotkeys(element, 'up up down down left right left right b a', () => console.log('konami code'))
hotkeys(element, '1', () => console.log('fire on keyup'), true)

// To unregister the listeners use the return function
const unregisterHotkeys = hotkeys(element, 'a', () => console.log('pressed a'))

unregisterHotkeys()

Available descriptors: ctrl shift alt altgr cmd enter tab space backspace escape capslock up down left right plus contextmenu delete insert pause home end numlock

Usage with react

Checkout react-piano-keys

Contributing

Yes, thank you.

License

MIT

About

A JavaScript shorcuts and hotkeys librairy

https://dherault.github.io/piano-keys/

License:MIT License


Languages

Language:TypeScript 76.9%Language:HTML 12.5%Language:JavaScript 10.6%