# keyboardevent-from-electron-accelerator

> Transform an Electron Accelerator string into a DOM KeyboardEvent.

Latest version **2.0.0** (published 2019-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install keyboardevent-from-electron-accelerator
pnpm add keyboardevent-from-electron-accelerator
yarn add keyboardevent-from-electron-accelerator
bun add keyboardevent-from-electron-accelerator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-11-08 |
| First published | 2017-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andrea |
| Maintainers | parroit |

## Links

- npm: https://www.npmjs.com/package/keyboardevent-from-electron-accelerator
- Repository: https://github.com/parro-it/keyboardevent-from-electron-accelerator
- Homepage: https://github.com/parro-it/keyboardevent-from-electron-accelerator#readme
- Issues: https://github.com/parro-it/keyboardevent-from-electron-accelerator/issues
- npm.io page: https://npm.io/package/keyboardevent-from-electron-accelerator

## Recent versions

- 2.0.0 (latest) — 2019-11-08
- 1.1.0 — 2018-01-02
- 1.0.1 — 2017-08-13
- 1.0.0 — 2017-08-13
- 0.7.1 — 2017-08-07
- 0.7.0 — 2017-07-27
- 0.6.0 — 2017-07-27
- 0.5.0 — 2017-07-05
- 0.4.0 — 2017-07-02
- 0.3.0 — 2017-06-29
- 0.1.0 — 2017-06-27
- 0.0.1 — 2017-06-27

## README

# keyboardevent-from-electron-accelerator

[![Travis Build Status](https://img.shields.io/travis/parro-it/keyboardevent-from-electron-accelerator/master.svg)](http://travis-ci.org/parro-it/keyboardevent-from-electron-accelerator)
[![NPM downloads](https://img.shields.io/npm/dt/keyboardevent-from-electron-accelerator.svg)](https://npmjs.org/package/keyboardevent-from-electron-accelerator)
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/l1qdd90e7xagkgq7/branch/master?svg=true)](https://ci.appveyor.com/project/parro-it/keyboardevent-from-electron-accelerator/branch/master)

> 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.

```js
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](https://github.com/parro-it/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](https://npm.runkit.com/keyboardevent-from-electron-accelerator) and [opening an issue](https://github.com/parro-it/keyboardevent-from-electron-accelerator/issues/new) if you found some wrong
result.


## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### toKeyEvent

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

**Parameters**

-   `accelerator` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** an Electron Accelerator string, e.g. `Ctrl+C` or `Shift+Space`.

Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a DOM KeyboardEvent object derivate from the `accelerator` argument.

## Install

With [npm](https://npmjs.org/) installed, run

    $ npm install keyboardevent-from-electron-accelerator

## See Also

-   [`noffle/common-readme`](https://github.com/noffle/common-readme)

## License

MIT

---
_Source: https://npm.io/package/keyboardevent-from-electron-accelerator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
