Simple tool that listens for keys to be hit in a certain order and calls a callback if the pattern matches.
keyPatternLogger = new KeyPatternLogger(
{
pattern: ["a", "b", "c"],
callback: function() {
console.log("It worked!");
}
}
)Accepts hash of parameters, pattern and callback.
patternis an array of keys, can be as many or as few as you likecallbackis 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.
If you want to stop the KeyPatternLogger from listening for matches,
you can call keyPatternLogger.stop() (and start it again with
keyPatternLogger.start())
Make sure dependencies are installed:
npm install -g mocha &
npm installRun with coffeescript compiler
mocha --compilers coffee:coffee-script/register