Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Key Pattern Logger

Simple tool that listens for keys to be hit in a certain order and calls a callback if the pattern matches.

Basic Example

keyPatternLogger = new KeyPatternLogger(
  {
    pattern: ["a", "b", "c"],
    callback: function() {
      console.log("It worked!");
    }
  }
)

Constructor Arguments

Accepts hash of parameters, pattern and callback.

  • pattern is an array of keys, can be as many or as few as you like
  • callback is a method with code that you want to execute when the pattern occurs.

Note: Modifier keys can also be checked for, e.g. "meta+a"

If the pattern consists of multiple keys, e.g. ["a", "b", "c"] the user needs to hit a, b, and c, in that order. If they hit any other key in-between, it isn’t a match.

If you only want to listen for one key, e.g. ["a"], that’s totally fine too. The callback will be called every single time someone hits the a key.

Stopping the KeyPatternLogger

If you want to stop the KeyPatternLogger from listening for matches, you can call keyPatternLogger.stop() (and start it again with keyPatternLogger.start())

Running the tests

Make sure dependencies are installed:

npm install -g mocha &
npm install

Run with coffeescript compiler

mocha --compilers coffee:coffee-script/register

About

Simple tool that listens for keys to be hit in a certain order and calls a callback if the pattern matches.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages