shortcut

Subscribe handlers to keyboard shortcuts

Shortcut

Assign functions to keypress events

var shortcut = require('shortcut')(process.stdin)

process.stdin.setRawMode(true)
process.stdin.resume()

shortcut('ctrl+c', process.exit)
shortcut('alt+a, shift+a, ctrl+a', function() { console.log('awesome') })
shortcut('meta+q', console.log.bind(null, 'queue', '...so meta'))

Installation

npm install shortcut

'shortcut': 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(event, handler): fn will be called with the keypress event and the handler

  • shift: , shift
  • ctrl: ^, ctrl, control
  • meta: , meta, alt, option

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

MIT