Registry / http-networking / keypress

keypress

JSON →
library0.1.7jsnpmunverified

The `keypress` package (version 0.2.1) is a JavaScript utility designed to make any Node.js `ReadableStream` emit "keypress" events. It was created to provide this functionality independently, particularly for Node.js `v0.8.x` where the `keypress` event on `process.stdin` was either undocumented or only emitted when used with the `readline` module. This module extracts and provides that specific logic. Released around 2012, this package is considered abandoned and is not maintained for modern Node.js environments. While it historically filled a gap for console applications requiring direct input handling, current Node.js versions offer built-in alternatives through the `readline` module's `emitKeypressEvents` method. It addresses a specific legacy need for low-level terminal input without relying on the full `readline` interface.

npm install keypress
INSTALL
IMPORT
SIG · KEYPRESS
K
keypress
http-networkingjavascriptv0.1.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

keypress
const keypress = require('keypress');
import keypress from 'keypress';
This package is CommonJS-only, as it was released prior to widespread ESM adoption in Node.js.
keypress function call
keypress(process.stdin);
const handler = new keypress.Handler();
The default export is a function that must be called with a ReadableStream to enable keypress events. It does not expose a class or other properties.
keypress type (TypeScript)
import keypress = require('keypress');
import type { Keypress } from 'keypress';
For TypeScript, a CommonJS-style import is required. There are no built-in type definitions, and `@types/keypress` refers to a different library. The package lacks official TypeScript support.

This example demonstrates how to enable and listen for "keypress" events on `process.stdin`, handling basic input and a Ctrl+C exit condition.

const keypress = require('keypress'); // make `process.stdin` begin emitting "keypress" events keypress(process.stdin); // enable raw mode for direct key input without waiting for Enter if (process.stdin.isTTY) { process.stdin.setRawMode(true); } // listen for the "keypress" event process.stdin.on('keypress', function (ch, key) { console.log('got "keypress" event:', ch, key); if (key && key.ctrl && key.name === 'c') { console.log('Ctrl+C pressed. Exiting.'); process.stdin.pause(); // Stop listening for input process.exit(); // Terminate the process } }); console.log('Press any key (Ctrl+C to exit)'); process.stdin.resume(); // Start listening for input
Debug
Known issues
breakingThis package was designed primarily for Node.js v0.8.x and earlier versions. Its behavior and necessity are highly inconsistent or deprecated in modern Node.js environments (Node.js 10+).
fix
For modern Node.js applications, use `readline.emitKeypressEvents(process.stdin)` and `process.stdin.setRawMode(true)` from the built-in `readline` module instead.
affects: >=1.0.0 (Node.js versions)
gotchaThe `keypress` function must be explicitly called with a `ReadableStream` (e.g., `process.stdin`) to initiate keypress event emission. Merely requiring the module does not activate the functionality.
fix
Ensure you call `keypress(yourReadableStream)` after requiring the module to enable events.
affects: *
deprecatedThe package is unmaintained, with its last release (0.2.1) dating back over a decade (circa 2012-2013). Using abandoned software introduces significant security risks due to unpatched vulnerabilities and lack of modern best practices.
fix
Migrate to Node.js's native `readline` module for keypress event handling or consider a actively maintained alternative like `emit-keypress` if additional features are needed.
affects: *
gotchaTo receive individual keypress events without waiting for the Enter key, the input stream (e.g., `process.stdin`) must be set to raw mode using `process.stdin.setRawMode(true)`.
fix
Add `process.stdin.setRawMode(true);` and `process.stdin.resume();` to your script before listening for keypress events. Remember to handle `process.exit()` or `process.stdin.pause()` to exit raw mode gracefully.
affects: *
Errors
Common errors & fixes
Error: require() is not defined in ES module scope
Attempting to use the CommonJS `require()` statement in a Node.js project configured to use ES Modules (e.g., via `"type": "module"` in `package.json` or `.mjs` files).
fix
Convert your project to CommonJS, or use a dynamic import workaround if absolutely necessary: `const keypress = await import('keypress'); keypress.default(process.stdin);`. However, migrating to `readline.emitKeypressEvents` is strongly recommended for ESM projects.
TypeError: keypress is not a function
The `keypress` module's default export is a function, not an object with methods. This error occurs if you try to access properties (e.g., `keypress.someMethod()`) on the imported `keypress` function.
fix
Call `keypress` directly as a function with your `ReadableStream` (e.g., `keypress(process.stdin)`) to enable keypress events. The events are then emitted on the stream itself, not the `keypress` object.
No 'keypress' event emitted on `process.stdin`
The `keypress` module was imported but its main function was not called with `process.stdin` to activate the event emitter, or `process.stdin.setRawMode(true)` was not enabled.
fix
Ensure both `keypress(process.stdin);` and `process.stdin.setRawMode(true); process.stdin.resume();` are called in your script before attaching an event listener to `process.stdin`.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
keypress — npm install keypress · libregistry