gulp-keylistener

0.1.11 • Public • Published

gulp-KeyListener

Adds a keys function to the gulp object which can be used for listening for/reacting to keystrokes..

This package is pretty much a simple mixture of Gulp.js and This npm module called keypress

Installation

npm:

$ npm i gulp-keylistener --save-dev

Usage:

Firstly, you must get your keys function from the gulp-keylistener package, like so:

const keys = require('gulp-keylistener')

Then you may use it like such:

// Our default task...
gulp.task('default', ()=> {
  keys((ch, key)=> {
// if you pressed `ctrl-p`
    if (key.ctrl && key.name === 'p') {
// Do amazing things!!!
    }
  })
})

-NOTE The listener does not listen system-wide. At this time, it only works within the context of the terminal. It can't, for example, 'hear' a keypress in the terminal made while working in a text-editor.

The keys() function takes a callback as it's only argument, and it takes 2 arguments -- ch (for character) and key. ch will give you access to a character value, i.e. 'a' or 'z' and key will give you an object that resembles thusly:

{
  name: 'x',
  ctrl: true,
  meta: false,
  shift: false,
  sequence: '\u0018'
}

By default, ctrl-x and ctrl-c will exit the process, which you will need to use, because the task you use keys() in will not finish on it's own. ctrl-w will pause the listener, so that you may exit or unpause the the process, but your callback will not be called, even if you hit your designated keybindings.

Admittedly this package is a bit on the hacky side, but it fulfills a unique purpose for me, and maybe it will for you as well. Happy Coding!!

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i gulp-keylistener

    Weekly Downloads

    1

    Version

    0.1.11

    License

    MIT

    Unpacked Size

    4.17 kB

    Total Files

    3

    Last publish

    Collaborators

    • ejames9