Create Custom Keyboard Shortcuts With JavaScript – Shortcuts

Category: Javascript | March 1, 2018
Author:rickellis
Views Total:3,076 views
Official Page:Go to website
Last Update:March 1, 2018
License:MIT

Preview:

Create Custom Keyboard Shortcuts With JavaScript – Shortcuts

Description:

Yet another JavaScript library to handle keyboard shortcuts that let you create events triggered by custom keyboard combinations.

Supported modifier keys:

  • CMD (Mac)
  • Ctrl
  • Alt
  • Shift

How to use it:

Insert the ‘shortcuts.js’ into the document and we’re ready to go.

<script src="shortcuts.js"></script>

Bind custom keyboard shortcuts and key presses as these:

shortcuts.add('shift+up',function() {
    alert('You pressed shift+up')
})
shortcuts.add('ctrl+5',function() {
    document.body.style.background = "#ffff00";
})
shortcuts.add('alt+k',function() {
    document.getElementById("foobar").innerText = "Hello there Earthling!"; 
})

You Might Be Interested In:


Leave a Reply