项目作者: cangzhang

项目描述 :
👂 for key combo and 🔥
高级语言: JavaScript
项目地址: git://github.com/cangzhang/key-combo-listener.git
创建时间: 2020-03-04T11:59:14Z
项目社区:https://github.com/cangzhang/key-combo-listener

开源协议:

下载


Key Combo Listener

👂 for key combo and 🔥.

With typescript support of course.

Installation

With yarn:

  1. yarn add key-combo-listener

With npm:

  1. npm install key-combo-listener --save

How to use

Use it like this:

  1. import keyComboListener from 'key-combo-listener';
  2. const keyCombo = ['ArrowUp', 'ArrowDown'];
  3. const timeout = 5000;
  4. const listener = keyComboListener(keyCombo, timeout, result => {
  5. if (result.done) {
  6. return console.log(`🔥 something!`);
  7. }
  8. console.log(`keep 👂`, result);
  9. })
  10. document.addEventListener(`keydown`, listener);

Configuration

key-combo-listener accepts 3 parameters.
| Param | Type | Default Value |
|—————|——————|———————-|
| key comb | string[] | [] |
| timeout | number(ms) | Infinity |
| callback | function | () => null |

TODO

  • typescript support