Skip to content

cangzhang/key-combo-listener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Key Combo Listener

πŸ‘‚ for key combo and πŸ”₯.

With typescript support of course.

Installation

With yarn:

yarn add key-combo-listener

With npm:

npm install key-combo-listener --save

How to use

Use it like this:

import keyComboListener from 'key-combo-listener';

const keyCombo = ['ArrowUp', 'ArrowDown'];
const timeout = 5000;
const listener = keyComboListener(keyCombo, timeout, result => {
    if (result.done) {
        return console.log(`πŸ”₯ something!`);
    }

    console.log(`keep πŸ‘‚`, result);
})

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