📜 ⬆️ ⬇️

Keymaster.js: a simple micro-library for hot keys

The keymaster.js library has appeared on guthub, with which you can add keyboard shortcuts (shortkuts) to any page. Of course, the jQuery Hotkeys module is designed for the same purposes, but keymaster.js has its advantages: this library has no dependencies, it is very lightweight (only 60 lines of code) and is deprived of the known jQuery Hotkeys bugs. In general, definitely a good thing.

In the near future for keymaster.js will add another selector INPUT / SELECT / TEXTAREA, it will also be a useful addition.

key('c', 'issues', function(){ console.log('c/issues'); }); key('command+r, ctrl+r', 'issues', function(){ console.log('Hijacked Command+R or Ctrl+R, damn!'); return false; }); key('i', function(){ keyScope('issues'); console.log('Switched to "issues" scope. Command+R or Ctrl+R is now no longer reloading...'); }); key('i', function(){ console.log('(example of multiple assignment)'); }); key('o, enter, left', function(){ console.log('o, enter or left pressed!'); }); key('ctrl+c', function(){ console.log('this is not the command line'); }); key('⌘+right,shift+left,ctrl+shift+alt+d', function(event){ console.log('command+right, or shift+left, or ctrl+shift+alt+d'); console.log('here is the event: ', event); return false; // prevent default && stop propagation }); 

Demo

')

Source: https://habr.com/ru/post/127285/


All Articles