keyboard event dispatcher.
JavaScript HTML Makefile
Latest commit 4bc96ed Jul 13, 2015 @yields Merge pull request #32 from matthewmueller/patch-1
update version
Failed to load latest commit information.
test fix tests Mar 19, 2015
.gitignore add ie7-9 support Jun 8, 2013 Release 0.7.2 Mar 19, 2015
Makefile use array for listeners Oct 30, 2013
package.json update version Jul 13, 2015
test.html tests: use mochas default reporter. Apr 9, 2014


keyboard event dispatcher.


$ component install yields/k


  • super keyword is command on mac and ctrl on anything else.
  • gmail like sequences (a b c *)
  • key combos
  • nice simple api
  • you can unbind anything you bind


var k = require('k')(window);

// combos
k('command + shift + enter', fn);

// on OSX `super` will be replaced with `command`
// on other operating systems it will be replaced with `ctrl`.
k('super + k', fn);

// sequences
k('a b c', fn);
k('* b c', fn);
k('super + shift + a b c', fn);



Create a new keyboard dispatcher on the given element

k(keys, fn)

Bind the given fn on keys.


the element k is listening on.


Bind keys with fn(e).


Unbind all listeners of keys, unbind fn with keys, unbind all listeners on all keys.

k.unbind(); // => unbind all listeners
k.unbind('enter'); // => unbind all enter listeners
k.unbind('command + enter'); // => unbind all `command + enter` listeners
k.unbind('command + enter', fn); // => unbind `fn` just from `command + enter`


Removes all listeners on k.el. Removes all k.listeners.


this function is called just before any handlers are called, if it returns true no handlers will be called for this event.

by default it returns true for input, textarea or select.

if you still want k to handle inputs you can k.ignore = false.


true if shiftKey is down.


true if ctrlKey is down.


true if alt is down.


true if command is down.


null if no modifiers are down, otherwise it's true.


true if command or ctrl are down (osx / others)


$ make test