keylogic
v1.0.2
Published
A frontend JavaScript package for managing keyboard shortcuts/events.
Readme
keylogic
A frontend JavaScript package for managing keyboard shortcuts/events.
📦 Installation
npm install keylogic --save🚀 Usage
Creating a keyboard shortcut:
createKeyShortcut(callback, ...keys)
// Being a default export, you can name this function whatever you want.
import createKeyShortcut from "keylogic";
// The first argument is a callback function for when the shortcut is pressed, and the rest define the keybinds.
const myShortcut = createKeyShortcut(
(event) => {
/* Your callback */
},
"control",
"alt",
"a"
);
// To unbind the shortcut, simply call:
myShortcut.unbind();
// To re-bind it later:
myShortcut.bind();⚠️ When calling createKeyShortcut, always use the key name(event.key), not the key code or any other identifier. Created shortcuts will attempt to block a default shortcut in your browser, if present.
🗝️ Supported Key Names
Letters:
a-zNumbers:
0-9Modifier keys:
control,alt,shift,meta(Windows key, Command key, Chromebook search key)Other common keys:
capslocktabenterescapebackspacearrowup,arrowdown,arrowleft,arrowright
Credits
Everything by Jacob Hackney.
