jQuery Plugin For Handling Keyboard Shortcut Events

File Size: 6.46 KB
Views Total: 2424
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin For Handling Keyboard Shortcut Events

keyboard-shortcuts.js is a super light jQuery plugin that allows the user to bind keyboard shortcut events to any element and when a key combination is pressed, an event is triggered following that keyboard shortcut. Supports modifier keys like shift, ctrl, alt, etc.

How to use it:

1. Include both jQuery library and the jQuery keyboard-shortcuts plugin's script on the webpage.

<script src="//code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="jquery.keyboard-shortcuts.js"></script>

2. Initialize the plugin and we're ready to go.

$(window).initKeyboard();

3. Binds custom keyboard shortcut events to the window element as follows:

$(window)
.on('Shift+▲', function(){
  // do something
}).on('Shift+▼', function(){
  // do something
})

4. Enable the debug mode to output the log in the console.

$(window).initKeyboard({debug:1})

This awesome jQuery plugin is developed by loganstellway. For more Advanced Usages, please check the demo page or visit the official website.