Bind Keyboard Shortcuts To Any Elements – KeyboardMaster

Category: Javascript | November 1, 2020
Author: sahithyandev
Views Total: 29 views
Official Page: Go to website
Last Update: November 1, 2020
License: MIT

Preview:

Bind Keyboard Shortcuts To Any Elements – KeyboardMaster

Description:

KeyboardMaster is a tiny, easy, and dependency-free JavaScript library that allows you to bind keyboard shortcuts to any DOM elements.

How to use it:

1. Download the package and import the main JavaScript into the HTML document.

<script src="./lib/index.js"></script>

2. Bind keyboard shortcuts to your element.

document.body.addKeyboardEvents({
  keyBindings: {
    seperator: ' + ',
    bindings: [
      {
        keyBinding: 'CTRL + ALT + A',
          action: () => {
            // do something      
          }
      },
      // more shortcuts here
    ]
  }
})

3. Use the library to enable a cheat code (e.g. Konami code) on your webpage.

document.body.addKeyboardEvents({
  passwordBindings: {
    timeout: -1,
    seperator: '-',
    bindings: [
      { 
        passwordBinding: 'c-s-s-s-c-r-i-p-t', 
        action: () => { 
          // do something
        } 
      }
    ]
  }
})

Changelog:

11/01/2020

  • Some bugs fixed

10/20/2020

  • Minor changes

You Might Be Interested In:


Leave a Reply