Input.js

A JavaScript library focused on sequential user inputs


How to use it

First you should include the minified file in your page.

After you have included the file, you have to instantiate a new Input object. If you do not specify an element, Input.js will by default attach the listener to the body element.

Input.js can also accept an element object and attach a listener to it.

Currently, Input.js provides limited number of public APIs for use.

ordered_combo let you link a sequence of keyup events to a function to be fired. If you do not provide a third parameter indicating how much time the listener shall wait for the sequence, it will wait there forever. Specify the time in seconds and make a call as the following. The sequence will only be valid for that time your specify when the first key of that sequence is fired.

The names of the keys you would have to use to register combos are the following:

Notice, you don't have to use uppercase letters. Lowercase letters are also fine. :)

delete_combo will unregister the combo you specify.

count_times will tell you how many times the provided sequence of keyup events has been fired.

delete_all will unregister all combos you have registered.


How it works

What happens when you call ordered_combo?

Input.js takes a record of the keys you have registered and store them as keys with the values of the number of times of them being registered.

Each registered combo is stored as a package with all the info needed.

Now the key point here is we are borrowing ideas from Nondeterministic finite automaton(NFA) to represent our transition states for registered sequences.


Cross browser

Some keycodes vary in different browsers. The follwing notes are NOT complete. They are incompatibilities I found at current stage.