kai-hotkeys
Simple JavaScript shortcuts and hotkeys library. This library has no dependencies and is very small in size (7 KB), compressed version - 4 KB. It is very easy to add, delete, change hotkeys or shortcuts.
Installation
npm install kai-hotkeys --save
Commands
hotkeys - is an object that has such methods:
- add(name, function, options) - add a hotkey
- change(name, name2, function2, options2) - change a hotkey
- change(name, name2, function2, options2) - delete
- is(name) - check for the existence of hotkey
- enable() - enable work
- disable() - disable work
Arguments:
- name - hotkey name
- function - function to be executed
- name2 - changed name
- function2 - changed function
- options { pressingOnce:false, // allows when the user releases the key to repeat the operation by pressing back }
Recommendation: use {pressingOnce:true} when your function is alert, confirm or prompt.
Usage
; hotkeys; hotkeys; hotkeys; // You can also enter the key code.// ctrl+shift+v, t e s thotkeys; // Using optionshotkeys; // Changing namehotkeys; // Changing name, function and optionshotkeys; // if you do not want to change any argument, insert - nullhotkeys; // Deleting hotkeyhotkeys; hotkeys; // Enable all hotkeyshotkeys; // Disable all hotkeyshotkeys;
Api
hotkeys.api has such methods:
- getHotkeys() - return all hotkeys
- getSpecialKeys() - return list of special keys
- getVisibleState() - return state of work (on/false)
- getIndex(name) - return index found name
Browser Support
Kai-hotkeys has been tested and should work in.
FirefoxChromeOperaEdge
Supported Keys
The following special keys can be used for shortcuts: ctrl, backspace, tab, enter, shift, alt, capslock, escape, left, up, right, down, delete.
Contributing
Any PR is welcome and will be reviewed.
License
MIT