keyboard event dispatcher


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

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