input.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html>
  3. <head><title>Input Test</title></head>
  4. <body>
  5. <br><br>
  6. Canvas:
  7. <span id="button-selection" style="display: none;">
  8. <input id="button1" type="button" value="L"><input id="button2" type="button" value="M"><input id="button4" type="button" value="R">
  9. </span>
  10. <br>
  11. <canvas id="canvas" width="640" height="20"
  12. style="border-style: dotted; border-width: 1px;">
  13. Canvas not supported.
  14. </canvas>
  15. <br>
  16. Results:<br>
  17. <textarea id="messages" style="font-size: 9;" cols=80 rows=25></textarea>
  18. </body>
  19. <!--
  20. <script type='text/javascript'
  21. src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
  22. -->
  23. <script src="../include/util.js"></script>
  24. <script src="../include/webutil.js"></script>
  25. <script src="../include/base64.js"></script>
  26. <script src="../include/keysym.js"></script>
  27. <script src="../include/keysymdef.js"></script>
  28. <script src="../include/keyboard.js"></script>
  29. <script src="../include/input.js"></script>
  30. <script src="../include/display.js"></script>
  31. <script>
  32. var msg_cnt = 0, iterations,
  33. width = 400, height = 200,
  34. canvas, keyboard, mouse;
  35. var newline = "\n";
  36. if (Util.Engine.trident) {
  37. var newline = "<br>\n";
  38. }
  39. function message(str) {
  40. console.log(str);
  41. cell = $D('messages');
  42. cell.textContent += msg_cnt + ": " + str + newline;
  43. cell.scrollTop = cell.scrollHeight;
  44. msg_cnt++;
  45. }
  46. function mouseButton(x, y, down, bmask) {
  47. msg = 'mouse x,y: ' + x + ',' + y + ' down: ' + down;
  48. msg += ' bmask: ' + bmask;
  49. message(msg);
  50. }
  51. function mouseMove(x, y) {
  52. msg = 'mouse x,y: ' + x + ',' + y;
  53. //console.log(msg);
  54. }
  55. function rfbKeyPress(keysym, down) {
  56. var d = down ? "down" : " up ";
  57. var key = keysyms.lookup(keysym);
  58. var msg = "RFB keypress " + d + " keysym: " + keysym;
  59. if (key && key.keyname) {
  60. msg += " key name: " + key.keyname;
  61. }
  62. message(msg);
  63. }
  64. function rawKey(e) {
  65. msg = "raw key event " + e.type +
  66. " (key: " + e.keyCode + ", char: " + e.charCode +
  67. ", which: " + e.which +")";
  68. message(msg);
  69. }
  70. function selectButton(num) {
  71. var b, blist = [1,2,4];
  72. if (typeof num === 'undefined') {
  73. // Show the default
  74. num = mouse.get_touchButton();
  75. } else if (num === mouse.get_touchButton()) {
  76. // Set all buttons off (no clicks)
  77. mouse.set_touchButton(0);
  78. num = 0;
  79. } else {
  80. // Turn on one button
  81. mouse.set_touchButton(num);
  82. }
  83. for (b = 0; b < blist.length; b++) {
  84. if (blist[b] === num) {
  85. $D('button' + blist[b]).style.backgroundColor = "black";
  86. $D('button' + blist[b]).style.color = "lightgray";
  87. } else {
  88. $D('button' + blist[b]).style.backgroundColor = "";
  89. $D('button' + blist[b]).style.color = "";
  90. }
  91. }
  92. }
  93. window.onload = function() {
  94. canvas = new Display({'target' : $D('canvas')});
  95. keyboard = new Keyboard({'target': document,
  96. 'onKeyPress': rfbKeyPress});
  97. Util.addEvent(document, 'keypress', rawKey);
  98. Util.addEvent(document, 'keydown', rawKey);
  99. Util.addEvent(document, 'keyup', rawKey);
  100. mouse = new Mouse({'target': $D('canvas'),
  101. 'onMouseButton': mouseButton,
  102. 'onMouseMove': mouseMove});
  103. canvas.resize(width, height, true);
  104. keyboard.grab();
  105. mouse.grab();
  106. message("Display initialized");
  107. if ('ontouchstart' in document.documentElement) {
  108. message("Touch device detected");
  109. $D('button-selection').style.display = "inline";
  110. $D('button1').onclick = function(){ selectButton(1) };
  111. $D('button2').onclick = function(){ selectButton(2) };
  112. $D('button4').onclick = function(){ selectButton(4) };
  113. selectButton();
  114. }
  115. }
  116. </script>
  117. </html>