@patomation/hotkey
v1.12.1
Published
Set hotkeys for web apps
Downloads
38
Maintainers
Readme
Hotkey
A small module that handles your hotkeys
Installation
npm install @patomation/hotkey
Usage
Supports using modifier keys in any order:
alt+ctrl+shift+p
for example, is the same as p+control+alt+shift
:
import { hotkey } from '@patomation/hotkey'
hotkey('control+z', () => {
//Do some undo action
});
Supports alpha numeric characters and more
hotkey('enter', () => {
//Do something when user hits enter
});
Add hotkey functions for arrow keys by using uparrow
, downarrow
, leftarrow
and rightarrow
hotkey('downarrow', () => {
//Down arrow function
});
new features
To have events for key up and key down. This is now supported.
hotkey('f')
.down(() => {
//Do something when f key is down
})
.up(() => {
//Do something when f key is up
})
Note: Adding up and down methods supports modifiers in hotkey commands. Additionally this could be written this way:
hotkey('shift+f', () => {
//Do something when f key is down
}).up(() => {
//Do something when f key is up
})
Development
- clone repo
- Install dependencies
npm install
- eslint:
npm run lint
- build lib folder with rollup with typescript overrides
npm run prebuild
View The files that will be published
npm pack && tar -xvzf *.tgz && rm -rf package *.tgz
Tests
npm test
Contributing
If you have any updates fork the repo and make a pull request.