strokerouter

A browser-side keystroke event router.

npm install strokerouter
8 downloads in the last month

strokerouter

strokerouter lets you hook functions up to keystrokes. It abstracts D3 key event handling.

Usage

var docStrokeRouter = createStrokeRouter(d3.select(document));

// Single key routes.
docStrokeRouter.routeKeyUp('escape', null, function escape() {
  console.log('Escape pressed.');
});
docStrokeRouter.routeKeyUp('u', null, function u() {
  console.log('U pressed.');
});

// Unroute a keystoke so that there is no longer a response to it.
docStrokeRouter.unrouteKeyUp('u', null);

Now when the user hits Esc or U, a message will be logged to the console.

See also: examples/basic.html.

Requirements

It depends on D3 v3.

Installation

npm install strokerouter

License

MIT.

npm loves you