A browser-side keystroke event router.


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

var docStrokeRouter = createStrokeRouter(;

// 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.

With Browserify:

var d3 = require('./my-d3-build'); // Or just: require('d3');
var createStrokeRouter = require('strokerouter', d3.event);
var docStrokeRouter = createStrokeRouter(;
// Etc.

It depends on D3 v3.

npm install strokerouter