Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keypress

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keypress

Make any Node ReadableStream emit "keypress" events

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
166K
decreased by-72.48%
Maintainers
1
Weekly downloads
 
Created

What is keypress?

The keypress npm package is used to handle keyboard events in Node.js applications. It allows developers to listen for and respond to keypress events, making it useful for creating interactive command-line applications.

What are keypress's main functionalities?

Listening for Keypress Events

This feature allows you to listen for keypress events on the standard input. The code sample demonstrates how to set up the keypress listener and handle specific keypress events, such as Ctrl+C to exit the process.

const keypress = require('keypress');

// make `process.stdin` begin emitting 'keypress' events
keypress(process.stdin);

// listen for the 'keypress' event
process.stdin.on('keypress', function (ch, key) {
  console.log('got "keypress" event', key);
  if (key && key.ctrl && key.name == 'c') {
    process.stdin.pause();
  }
});

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

Handling Special Keys

This feature allows you to handle special keys like arrow keys. The code sample demonstrates how to detect and respond to different arrow key presses.

const keypress = require('keypress');

// make `process.stdin` begin emitting 'keypress' events
keypress(process.stdin);

// listen for the 'keypress' event
process.stdin.on('keypress', function (ch, key) {
  if (key) {
    switch (key.name) {
      case 'up':
        console.log('up arrow key pressed');
        break;
      case 'down':
        console.log('down arrow key pressed');
        break;
      case 'left':
        console.log('left arrow key pressed');
        break;
      case 'right':
        console.log('right arrow key pressed');
        break;
    }
  }
});

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

Other packages similar to keypress

Keywords

FAQs

Package last updated on 17 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc