Skip to content

Commit

Permalink
add click
Browse files Browse the repository at this point in the history
  • Loading branch information
Banaanae committed Oct 12, 2024
1 parent 469cdd6 commit bba1187
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 69 deletions.
212 changes: 143 additions & 69 deletions blocks/kbm.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,144 @@
import * as Blockly from 'blockly';

export const kbAndMouse = Blockly.common.createBlockDefinitionsFromJsonArray([
{
"type": "send",
"message0": "Send %1",
"args0": [
{
"type": "input_value",
"name": "send_keys"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Send a key",
"helpUrl": ""
},
{
"type": "sendmode",
"message0": "Set Send Mode to %1",
"args0": [
{
"type": "field_dropdown",
"name": "sendmode_type",
"options": [
[
"Event",
"Event"
],
[
"Input",
"Input"
],
[
"InputThenPlay",
"InputThenPlay"
],
[
"Play",
"Play"
]
]
}
],
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Changes how key and mouse inputs are sent",
"helpUrl": ""
},
{
"type": "setdefaultmousespeed",
"message0": "SetDefaultMouseSpeed %1",
"args0": [
{
"type": "input_value",
"name": "INPUT",
"check": "Number"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Sets the default mouse movement speed (between 0-100)",
"helpUrl": "https://www.autohotkey.com/docs/v2/lib/SetDefaultMouseSpeed.htm"
}
import * as Blockly from 'blockly';

export const kbAndMouse = Blockly.common.createBlockDefinitionsFromJsonArray([
{
"type": "send",
"message0": "Send %1",
"args0": [
{
"type": "input_value",
"name": "send_keys"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Send a key",
"helpUrl": ""
},
{
"type": "sendmode",
"message0": "Set Send Mode to %1",
"args0": [
{
"type": "field_dropdown",
"name": "sendmode_type",
"options": [
[
"Event",
"Event"
],
[
"Input",
"Input"
],
[
"InputThenPlay",
"InputThenPlay"
],
[
"Play",
"Play"
]
]
}
],
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Changes how key and mouse inputs are sent",
"helpUrl": ""
},
{
"type": "setdefaultmousespeed",
"message0": "SetDefaultMouseSpeed %1",
"args0": [
{
"type": "input_value",
"name": "INPUT",
"check": "Number"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Sets the default mouse movement speed (between 0-100)",
"helpUrl": "https://www.autohotkey.com/docs/v2/lib/SetDefaultMouseSpeed.htm"
},
{
"type": "click",
"message0": "Send %1 mouse button %2 at X: %3 Y: %4 ​ %5 times %6 Relative",
"args0": [
{
"type": "field_dropdown",
"name": "button",
"options": [
[
"left",
"left"
],
[
"right",
"right"
],
[
"middle",
"middle"
],
[
"4th",
"x1"
],
[
"5th",
"x2"
]
]
},
{
"type": "field_dropdown",
"name": "type",
"options": [
[
"click",
"click"
],
[
"down",
"down"
],
[
"up",
"up"
]
]
},
{
"type": "input_value",
"name": "x"
},
{
"type": "input_value",
"name": "y"
},
{
"type": "input_value",
"name": "times"
},
{
"type": "field_checkbox",
"name": "rel",
"checked": "FALSE"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": 90,
"tooltip": "Click at the specified coordinates using the set mouse button",
"helpUrl": ""
}

])
17 changes: 17 additions & 0 deletions codeGen/blockDef.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ export function a_setbuiltin(block, generator) {
return `${a_var} := ${a_to}`
}

export function click(block, generator) {
const button = block.getFieldValue('button')
let type = block.getFieldValue('type')
if (type === "click") {
type = ""
}
const x = generator.valueToCode(block, 'x', Order.ATOMIC)
const y = generator.valueToCode(block, 'y', Order.ATOMIC)
const times = generator.valueToCode(block, 'times', Order.ATOMIC)
const relative = block.getFieldValue('rel')
let rel = "";
if (relative === "TRUE") {
rel = " rel"
}
return `Click(${x}, ${y}, "${times} ${button} ${type}${rel}")` // TODO: Spacing
}

export function colour_picker(block, generator) {
const colour = block.getFieldValue('COLOUR')
return colour
Expand Down
4 changes: 4 additions & 0 deletions toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const toolbox = {
{
"kind": "block",
"type": "setdefaultmousespeed"
},
{
"kind": "block",
"type": "click"
}
]
},
Expand Down

0 comments on commit bba1187

Please sign in to comment.