Create Custom Keyboard Shortcuts With JavaScript – Shortcuts

Category: Javascript | March 1, 2018
Authorrickellis
Last UpdateMarch 1, 2018
LicenseMIT
Views3,117 views
Create Custom Keyboard Shortcuts With JavaScript – Shortcuts

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