123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 'use strict';
- goog.provide('Blockly.Python.hci');
- goog.require('Blockly.Python');
- /* HID
- * setup
- */
- Blockly.Python['HID_setup'] = function(block) {
- Blockly.Python.addInclude('keyboard', '#include \"Keyboard.h\"');
- Blockly.Python.addInclude('Mouse', '#include \"Mouse.h\"');
- Blockly.Python.addSetup("HID", "Mouse.begin();\n" +
- "Keyboard.begin();\n");
- return "";
- }
- /* HID
- * mouse move
- */
- Blockly.Python['HID_mouse_move'] = function(block) {
- var code = "";
- var mouse_moveTowards = block.getFieldValue("mouse_towards");
- var mouse_moveDistance = block.getFieldValue("mouse_distance");
- switch (mouse_moveTowards) {
- case "KEYPAD_UP":
- code = "Mouse.move(0, -" + mouse_moveDistance + ");\n";
- break;
- case "KEYPAD_DOWN":
- code = "Mouse.move(0, " + mouse_moveDistance + ");\n";
- break;
- case "KEYPAD_LEFT":
- code = "Mouse.move(-" + mouse_moveDistance + ", 0);\n";
- break;
- case "KEYPAD_RIGHT":
- code = "Mouse.move(" + mouse_moveDistance + ", 0);\n";
- break;
- }
- return code;
- }
- /* HID
- * mouse click
- */
- Blockly.Python['HID_mouse_click'] = function(block) {
- var click = block.getFieldValue("CLICK");
- var code = "Mouse.click(" + click + ");\n";
- return code;
- }
- /* HID
- * mouse press
- */
- Blockly.Python['HID_mouse_press'] = function(block) {
- var click = block.getFieldValue("CLICK");
- var code = "Mouse.press(" + click + ");\n";
- return code;
- }
- /* HID
- * mouse release
- */
- Blockly.Python['HID_mouse_release'] = function(block) {
- var click = block.getFieldValue("CLICK");
- var code = "Mouse.release(" + click + ");\n";
- return code;
- }
- /* HID
- * keyboard press
- */
- Blockly.Python['HID_keyboard_press'] = function(block) {
- var key = block.getFieldValue("keyboard_press");
- var code = "Keyboard.press(" + key + ");\n";
- return code;
- }
- /* HID
- * keyboard release
- */
- Blockly.Python['HID_keyboard_release'] = function(block) {
- var key = block.getFieldValue("keyboard_press");
- var code = "Keyboard.release(" + key + ");\n";
- return code;
- }
- /* HID
- * keyboard release all
- */
- Blockly.Python['HID_keyboard_releaseAll'] = function(block) {
- var code = "Keyboard.releaseAll();\n";
- return code;
- }
|