node package manager


Subscribe handlers to keyboard shortcuts


Assign functions to keypress events

var shortcut = require('../shortcut')(process.stdin)
// shortcut assignment 
shortcut('ctrl+c', process.exit)
// multiple shortcuts bound to one function 
shortcut('alt+a, shift+a, ctrl+a', function() { 
// get event and handler data 
shortcut('b, ⇧+b, ^+b, ⌥+b', function(e, handler) {
  console.log(handler.shortcut+': fired!')
npm install shortcut

If the ReadableStream is not emiting keypress events then the stream will be passed into keypress

Returns the shortcut library listening to ReadableStream

  • string: A combination of Modifiers joined by + and terminated with a single key. You can join shortcuts with a comma , to assign multiple to one function.
  • fn: Will be called with the keypress event and the shortcut handler
  • shift: , shift
  • ctrl : ^, ctrl, control
  • meta : , meta, alt, option

This module is heavily inspired by Thomas Fuchs' keymaster library.