my-key-config
My UI written with Web Components for key config for me.
Installation
$ npm install my-key-config
Usage
Use the key config component
In your HTML:
Then initialize the component:
; // Register the custom elements defined by key-config.; // Initialize a store to save key config.const store = 'prefix';// const store = new ChromeStorageStore('prefix'); // Define keyboard shortcuts.const spec = id: 'save' name: 'Save to File' // Default config (optional; no shortcut if not specified) default: key: 'S' shiftKey: false ctrlKey: true altKey: false metaKey: false id: 'quit' name: 'Quit' default: key: 'Q' shiftKey: false ctrlKey: true altKey: false metaKey: false ; const kc = document; kc;
Listen to key shortcuts
; // Initialize the store.const store = 'prefix'; // Also spec.const spec = id: 'save' name: 'Save to File' // Default config (optional; no shortcut if not specified) default: key: 'S' shiftKey: false ctrlKey: true altKey: false metaKey: false id: 'quit' name: 'Quit' default: key: 'Q' shiftKey: false ctrlKey: true altKey: false metaKey: false ; // Initialize KeyListener with store and spec.const listener = store spec; // Start listening to the 'keydown' event.listener; // KeyListener implements the EventTarget API.listener;// `onkey` property can also be used// listener.onkey = (event)=> console.log('hi');
License
MIT © uhyo