Skip to content
Utility for creating keyboard shortcuts
JavaScript
Find file
Latest commit b7f0394 @mzabriskie Updating README
Failed to load latest commit information.
dist
src Adding dist/
.gitignore
CHANGELOG.md
Gruntfile.js
README.md
bower.json Bumping version
index.html
package.json Bumping version

README.md

keymap.js

Utility for creating keyboard shortcuts

Installing

$ bower install keymap.js

Examples

Create a Keymap using a single character:

Keymap.create('j', function () { alert('next'); });
Keymap.create('k', function () { alert('prev'); });

Create a Keymap using a character sequence:

Keymap.create('foo', function () { alert('bar'); });

Create a Keymap using a single char code:

Keymap.create(Keymap.keyCode.ESC, function () { alert('cancel'); });

Create a Keymap using a char code sequence:

Keymap.create([
    Keymap.keyCode.UP,
    Keymap.keyCode.UP,
    Keymap.keyCode.DOWN,
    Keymap.keyCode.DOWN,
    Keymap.keyCode.LEFT,
    Keymap.keyCode.RIGHT,
    Keymap.keyCode.LEFT,
    Keymap.keyCode.RIGHT,
    Keymap.keyCode.B,
    Keymap.keyCode.A], function () { alert('konami'); });

By default Keymap.create auto enables the instance. There may be times when you don't want this behavior.

// Create a Keymap that is disabled
var keymap = Keymap.create(Keymap.keyCode.ESC, {
    callback: function () { alert('cancel'); },
    enabled: false
});

// Enable it at a later point
keymap.enable();

API

Instance methods

enable()

Enable the Keymap

disable()

Disable the Keymap

reset()

Reset the Keymap

Static methods

create(code, options)

Create a new Keymap

options
  • callback - The function that will be invoked when the code is met
  • timeout - How long between key strokes before reset is called (defaults to 500)
  • enabled - Whether or not the Keymap should be enabled (defaults to true)
Note

Options can be either a function, or an object. If a function is provided it will be used as the callback option, and other options will use default values.

License

keymap.js is released under the MIT license.

Something went wrong with that request. Please try again.