เป็นไปได้ไหมที่จะฟังการกดแป้นพิมพ์ขาเข้าในสคริปต์ nodejs ที่กำลังรันอยู่ หากฉันใช้process.openStdin()และฟัง'data'เหตุการณ์ของมันอินพุตจะถูกบัฟเฟอร์จนกว่าจะขึ้นบรรทัดใหม่ถัดไปดังนี้:
// stdin_test.js
var stdin = process.openStdin();
stdin.on('data', function(chunk) { console.log("Got chunk: " + chunk); });
วิ่งสิ่งนี้ฉันได้รับ:
$ node stdin_test.js
                <-- type '1'
                <-- type '2'
                <-- hit enter
Got chunk: 12
สิ่งที่อยากเห็น:
$ node stdin_test.js
                <-- type '1' (without hitting enter yet)
 Got chunk: 1
ฉันกำลังมองหา nodejs ที่เทียบเท่ากับเช่นgetcในทับทิม
เป็นไปได้หรือไม่