Tuesday, 2 October 2018

node.js: readline.emitKeypressEvents(stream[, interface])

readline.emitKeypressEvents(stream[, interface])
This method causes the given Readable stream to begin emitting 'keypress' events.

Below table summarizes the arguments of the method.
Argument
Type
Description
stream
stream.Readable
Stream that emits key press vents
interface
readline.Interface
It specifies a readline.Interface instance for which autocompletion is disabled when copy-pasted input is detected.

HelloWorld.js
var readline = require('readline')

// If the stream is TTY, then it must  be in RAW mode
if (process.stdin.isTTY)
  process.stdin.setRawMode(true);

var rl = readline.createInterface({
 input: process.stdin,
 output: process.stdout
});

readline.emitKeypressEvents(process.stdin)
process.stdin.on('keypress', () => {
    process.stdout.write('.')
})


Whenever you type something, keypress event is emitted and print a ‘.’.

Note
If the stream is a TTY, then it must be in raw mode.




Previous                                                 Next                                                 Home

No comments:

Post a Comment