A small module that handles your hotkeys
npm install @patomation/hotkey
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
});
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
})
- clone repo
- Install dependencies
npm install
- eslint:
npm run lint
- build lib folder with rollup with typescript overrides
npm run prebuild
npm pack && tar -xvzf *.tgz && rm -rf package *.tgz
npm test
If you have any updates fork the repo and make a pull request.