mdogadailo / keyboardevent-from-electron-accelerator

Transform an Electron Accelerator string into a DOM KeyboardEvent.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Travis Build Status NPM downloads AppVeyor Build status

Transform an Electron Accelerator string into a DOM KeyboardEvent.

This module export a function that take an Electron Accelerator as input and return a corresponding KeyboardEvent object.

E.g. 'Ctrl+Alt+C' => {code: 'c', ctrlKey: true, altKey: true}


This example convert a string containing an Electron Accelerator to a corresponding KeyboardEvent object. Returned object is the keyevent that would be emitted if that key combination was pressed.

const {toKeyEvent} = require('keyboardevent-from-electron-accelerator');

This will output

{key: 'Delete', shiftKey: true}

Context and motivation for this module.

This module is part of an ongoing effort to make electron-localshortcut less error prone, using keyboard DOM listener instead of 'globalShortcut' method to trigger shortcuts handlers.

electron-localshortcut will listen for DOM keydown and keyup events, and will trigger shortcuts handlers if emitted DOM events match the Accelerator.

This module wrap the core logic of that match operation.

You can help by testing the module on runkit and opening an issue if you found some wrong result.



This function transform an Electron Accelerator string into a DOM KeyboardEvent object.


  • accelerator string an Electron Accelerator string, e.g. Ctrl+C or Shift+Space.

Returns object a DOM KeyboardEvent object derivate from the accelerator argument.


With npm installed, run

$ npm install keyboardevent-from-electron-accelerator

See Also



ezoic increase your site revenue


Transform an Electron Accelerator string into a DOM KeyboardEvent.

License:MIT License


Language:JavaScript 100.0%