td-set-shortcuts

1.3.26 • Public • Published

A javascript package to set shortcuts, and callbacks.

  • Supports nested key order.
  • Supports focus mode.

installation

Install the npm package:

npm i td-set-shortcuts

And:

window.setShortcut = require('td-set-shortcuts');

Usage

// Set shortcuts
let shortcuts = {
   'ControlLeft': {
      'KeyH': () => {
         console.log("Hello World!");
      },
      '*': (e) => {
         if(e.key !== 'h') console.log("You pressed [control + other keys]!");
      },
   }
};

// Set the block in which commands should be executed (default: document).
let block = document;

// Set if the block is focused by default or not. (default: true).
let is_focused = true;

// Set if preventDefault should be executed (default: true)
let prevent_default = true;

// Run the package.
setShortcut(shortcuts, block, is_focused, prevent_default);

Note: Do not use alert in callback functions. When alert is executed, the keyup won't get fired, and the library won't work correctly.

Package Sidebar

Install

npm i td-set-shortcuts

Weekly Downloads

0

Version

1.3.26

License

MIT

Unpacked Size

8.45 kB

Total Files

4

Last publish

Collaborators

  • hamedgasemi200