Advertisement
icebowl

nodejs-eventloop.js

Jun 15th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. const readline = require('readline');// https://nodejs.org/api/readline.html
  2. readline.emitKeypressEvents(process.stdin);//https://nodejs.org/api/readline.html#readline_readline_emitkeypressevents_stream_interface
  3. process.stdin.setRawMode(true);
  4.  
  5. function showKey(str,count) {
  6. process.stdout.write(str+" ");
  7. if(count % 30 === 0) process.stdout.write("\n");
  8. }
  9.  
  10.  
  11. //main
  12. var count = 0;
  13. process.stdin.on('keypress', (str, key) => {
  14. if (key.ctrl && key.name === 'c') {
  15. process.exit();
  16. } else {
  17. showKey(str,count);
  18. count++;
  19. }
  20. });
  21. console.log('Press any key...');
  22.  
  23.  
  24. //notes:
  25. // rund node code https://npm.runkit.com/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement