1.0.9 • Published 4 years ago

shortcutifier v1.0.9

Weekly downloads
24
License
GNP3
Repository
-
Last release
4 years ago

Shortcutifier

A small lib to help with registering shortcuts on a webpage without impacting performance

Code example:

The callback is called when all key specified in the shortcut are pressed simultaneously

import ShortcutHandler from 'shortcutifier';

const keys = [65, 90]; // array of keycodes
const callback = () => {console.log('A & Z were pressed a the same time')}; // callback when all keys are pressed simultaneously

const handler = new ShortcutHandler();
handler.subscribeShortcut(keys, callback);

The subscribeShortcut method also return a function to remove the shortcut

const unsubscribe = handler.subscribeShortcut(keys, callback);
unsubscribe(); // remove the shortcut

Infos

The event handler automatically remove the keypress listeners when no shortcuts are currently subscribed.

Callback is only called once per shortcut press to avoid mistakenly spamming when holding the shortcut.

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago