How to use the keypress function in keypress

To help you get started, we’ve selected a few keypress examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rauchg / clif / lib / index.js View on Github external
toolbar: this.toolbar,
      quality: this.quality
    });

    env = clone(env || process.env);
    env.TERM = env.TERM || 'xterm-256color';

    this.pty = pty(shell, argv, {
      cwd: cwd,
      rows: this.rows,
      columns: this.cols,
      env: env
    });

    // in
    if (this.keys) keypress(process.stdin);
    this.rawState = process.stdin.isRaw;
    process.stdin.setRawMode(true);
    process.stdin.resume();
    process.stdin.pipe(this.pty.stdin);
    process.stdin.on('keypress', (c, k) => this.key(c, k));

    // out
    this.pty.stdout.on('data', buf => this.out(buf));
    this.pty.on('exit', () => this.complete());

    // poll title
    if (this.toolbar) this.getTitle();
  }
github guo-yu / player / libs / cli.js View on Github external
var beginWith = str.charAt(0)
    if (beginWith === '~' || beginWith == '/')
      return true

    return false
  }

  var vol = 1

  function updateVolume() {
    player.setVolume(vol)
    console.log('volume: ' + Math.floor(vol * 100))
  }

  keypress(process.stdin);

  var paused = false

  process.stdin.on('keypress', function (ch, key) {
    if (key && key.ctrl && key.name == 'c') {
      process.exit(0)
    }
    if (key && key.name == 'space') {
      player.pause()
      if(!paused)
        console.log('paused')
      else
        console.log('resuming')
      paused = !paused
    }
    if (key && key.name == 'x') {
github Urucas / ScreenRec / lib / index.js View on Github external
wait4key() {
    
    if(this.options.silent == false) console.log("Press [ctrl + c] to stop recording".white);
    let key = keypress(process.stdin);
    let self = this;

    process.stdin.on('keypress', function (ch, key) {
      if (key && key.ctrl && key.name == 'c') {
        process.stdin.pause();
        self.stop();
      }
    });
  
    process.stdin.setRawMode(true);
    process.stdin.resume();
  }
github azproduction / node-mc / lib / tui-terminal / lib / tui-events.js View on Github external
_activateKeyboardEvents() {
        keypress(this._stdin);

        this._stdin.on('keypress', (character, key) => {
            this.emit('event', this._translateKeyboardEvent('keypress', character, key));
        });

        this._stdin.setRawMode(true);
        this._stdin.resume();
    }
github rizowski / eslint-watch / src / index.js View on Github external
function keyListener(args, options) {
  let stdin = process.stdin;
  if (!stdin.setRawMode) {
    logger.debug('Process might be wrapped exiting keybinding');
    return;
  }
  keypress(stdin);
  stdin.on('keypress', function keyPressListener(ch, key) {
    logger.debug('%s was pressed', key ? key.name : ch);
    if (key && key.name === 'return') {
      logger.debug('relinting...');
      logger.debug(options);
      runLint(args, options);
    }
    if (key && key.ctrl && key.name === 'c') {
      process.exit();
    }
  });
  stdin.setRawMode(true);
  stdin.resume();
}
github JonathanUsername / nplaym / src / io.js View on Github external
});

  npm.on('close', d => {
    gameOver(true);
  });

  process.on('exit', function () {
    npm.kill('SIGINT');
    term.showCursor();
  });

  process.stdin.setRawMode(true);

  term.hideCursor();

  keypress(process.stdin);

  process.stdin.on('keypress', function (chunk, key) {
    if (!key) return; 
    if (key.ctrl && key.name == 'c') {
      process.exit(1);
    }
    switch (key.name) {
      case 'left':
        term.right(1);
        player.left = Math.max(player.left - 1, LEFTWALL);
      break;
      case 'right':
        term.left(1);
        player.left = Math.min(player.left + 1, WIDTH - RIGHTWALL);
      break;
      case 'space':
github kjirou / escape-from-the-maze / input / AppInput.es6 View on Github external
import keypress from 'keypress';
import Rx from 'rx';

import {onError} from 'input/subscriptions/error';
import {onKeypress} from 'input/subscriptions/keypress';
import {onTimer} from 'input/subscriptions/timer';
import SingletonMixin from 'lib/mixins/SingletonMixin';
import {calculateMillisecondsPerFrame} from 'lib/util';

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


export default class AppInput {

  constructor() {
    let pauser = new Rx.Subject();

    let timerSource = Rx.Observable
      .timer(0, calculateMillisecondsPerFrame())
      .timeInterval()
      .map((data) => {
        pauser.onNext(true);
        return data;
      })

keypress

Make any Node ReadableStream emit "keypress" events

MIT
Latest version published 11 years ago

Package Health Score

65 / 100
Full package analysis