keyboard_tty.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. function NodeKeyboardTTY()
  3. {
  4. var stdin = process.stdin;
  5. var send_code;
  6. var charmap = [
  7. // TODO: Fill this in or get it from somewhere
  8. ];
  9. //stdin.setRawMode(true);
  10. stdin.resume();
  11. stdin.setEncoding('utf8');
  12. this.enabled = true;
  13. this.destroy = function()
  14. {
  15. };
  16. this.init = function(send_code_fn)
  17. {
  18. send_code = send_code_fn;
  19. };
  20. stdin.on("data", function(c)
  21. {
  22. if(c === '\u0003')
  23. {
  24. process.exit();
  25. }
  26. var str = "";
  27. for(var i = 0; i < c.length; i++)
  28. {
  29. str += c.charCodeAt(i);
  30. }
  31. //dbg_log(str);
  32. dbg_log("2 " + JSON.stringify(arguments));
  33. });
  34. stdin.on("keypress", function(c)
  35. {
  36. if(c === '\u0003')
  37. {
  38. process.exit();
  39. }
  40. dbg_log("keypress: " + JSON.stringify(arguments));
  41. var code = charmap[c.charCodeAt(0)];
  42. send_code(code);
  43. //send_code(code | 0x80);
  44. });
  45. }