Skip to content

Instantly share code, notes, and snippets.

@newvertex
Created September 17, 2016 10:24
Example: Detect keypress event in Node.js console app
var readline = require('readline');
readline.emitKeypressEvents(process.stdin);
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
process.stdin.on('keypress', (chunk, key) => {
if (key && key.name == 'q')
process.exit();
});
@etherealHero
Copy link

👍

@tfrank11
Copy link

🐐

@stevemu
Copy link

stevemu commented Oct 24, 2024

Thank you!

@5aurabh
Copy link

5aurabh commented Mar 29, 2025

Thanks for this. Is there a standard way to detect a keyrelease event or do we need to rely on some timeout logic which tracks inactivity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment