Giter VIP home page Giter VIP logo

keyboardevent-from-electron-accelerator's Introduction

keyboardevent-from-electron-accelerator

Travis Build Status NPM downloads

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}

Usage

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');
console.log(toKeyEvent('Shift+Delete'));

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.

API

toKeyEvent

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

Parameters

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

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

Install

With npm installed, run

$ npm install keyboardevent-from-electron-accelerator

See Also

License

MIT

keyboardevent-from-electron-accelerator's People

Contributors

parro-it avatar

Watchers

James Cloos avatar Jimmie Hansson (aka. ch0wndevil) avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.