hci.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. 'use strict';
  2. goog.provide('Blockly.Python.hci');
  3. goog.require('Blockly.Python');
  4. /* HID
  5. * setup
  6. */
  7. Blockly.Python['HID_setup'] = function(block) {
  8. Blockly.Python.addInclude('keyboard', '#include \"Keyboard.h\"');
  9. Blockly.Python.addInclude('Mouse', '#include \"Mouse.h\"');
  10. Blockly.Python.addSetup("HID", "Mouse.begin();\n" +
  11. "Keyboard.begin();\n");
  12. return "";
  13. }
  14. /* HID
  15. * mouse move
  16. */
  17. Blockly.Python['HID_mouse_move'] = function(block) {
  18. var code = "";
  19. var mouse_moveTowards = block.getFieldValue("mouse_towards");
  20. var mouse_moveDistance = block.getFieldValue("mouse_distance");
  21. switch (mouse_moveTowards) {
  22. case "KEYPAD_UP":
  23. code = "Mouse.move(0, -" + mouse_moveDistance + ");\n";
  24. break;
  25. case "KEYPAD_DOWN":
  26. code = "Mouse.move(0, " + mouse_moveDistance + ");\n";
  27. break;
  28. case "KEYPAD_LEFT":
  29. code = "Mouse.move(-" + mouse_moveDistance + ", 0);\n";
  30. break;
  31. case "KEYPAD_RIGHT":
  32. code = "Mouse.move(" + mouse_moveDistance + ", 0);\n";
  33. break;
  34. }
  35. return code;
  36. }
  37. /* HID
  38. * mouse click
  39. */
  40. Blockly.Python['HID_mouse_click'] = function(block) {
  41. var click = block.getFieldValue("CLICK");
  42. var code = "Mouse.click(" + click + ");\n";
  43. return code;
  44. }
  45. /* HID
  46. * mouse press
  47. */
  48. Blockly.Python['HID_mouse_press'] = function(block) {
  49. var click = block.getFieldValue("CLICK");
  50. var code = "Mouse.press(" + click + ");\n";
  51. return code;
  52. }
  53. /* HID
  54. * mouse release
  55. */
  56. Blockly.Python['HID_mouse_release'] = function(block) {
  57. var click = block.getFieldValue("CLICK");
  58. var code = "Mouse.release(" + click + ");\n";
  59. return code;
  60. }
  61. /* HID
  62. * keyboard press
  63. */
  64. Blockly.Python['HID_keyboard_press'] = function(block) {
  65. var key = block.getFieldValue("keyboard_press");
  66. var code = "Keyboard.press(" + key + ");\n";
  67. return code;
  68. }
  69. /* HID
  70. * keyboard release
  71. */
  72. Blockly.Python['HID_keyboard_release'] = function(block) {
  73. var key = block.getFieldValue("keyboard_press");
  74. var code = "Keyboard.release(" + key + ");\n";
  75. return code;
  76. }
  77. /* HID
  78. * keyboard release all
  79. */
  80. Blockly.Python['HID_keyboard_releaseAll'] = function(block) {
  81. var code = "Keyboard.releaseAll();\n";
  82. return code;
  83. }