From b026b484f7f4fde19ca02c14e8016ffb970ccea6 Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 20 Jan 2025 23:00:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E9=BC=A0=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=A2=9E=E5=8A=A0=E5=BE=AA=E7=8E=AF=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/lib/quickcomposer/simulate/index.js | 2 + .../lib/quickcomposer/simulate/mouseClick.js | 18 ++++ src/js/composer/commands/simulateCommands.js | 87 ++++++++++++------- 3 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 plugin/lib/quickcomposer/simulate/mouseClick.js diff --git a/plugin/lib/quickcomposer/simulate/index.js b/plugin/lib/quickcomposer/simulate/index.js index f8bc9f9..941d1fe 100644 --- a/plugin/lib/quickcomposer/simulate/index.js +++ b/plugin/lib/quickcomposer/simulate/index.js @@ -2,6 +2,7 @@ const { findImage } = require("./imageFinder"); const { keyboardTap, keySequence } = require("./keyboardTap"); const { screenColorPick } = require("./screenColorPick"); const screenCapture = require("./screenCapture"); +const mouseClick = require("./mouseClick"); module.exports = { findImage, @@ -9,5 +10,6 @@ module.exports = { keyboardTap, keySequence, screenColorPick, + mouseClick, ...screenCapture, }; diff --git a/plugin/lib/quickcomposer/simulate/mouseClick.js b/plugin/lib/quickcomposer/simulate/mouseClick.js new file mode 100644 index 0000000..65b029d --- /dev/null +++ b/plugin/lib/quickcomposer/simulate/mouseClick.js @@ -0,0 +1,18 @@ +const mouseClick = (mouseAction = "Click", options) => { + const { x, y, count = 1, interval = 0 } = options; + let mouseActionFn = () => {}; + if (x !== undefined && y !== undefined) { + mouseActionFn = () => utools["simulateMouse" + mouseAction](x, y); + } else { + mouseActionFn = () => utools["simulateMouse" + mouseAction](); + } + + for (let i = 0; i < count; i++) { + mouseActionFn(); + if (interval > 0 && i < count - 1) { + quickcommand.sleep(interval); + } + } +}; + +module.exports = mouseClick; diff --git a/src/js/composer/commands/simulateCommands.js b/src/js/composer/commands/simulateCommands.js index 0a0f70d..8d6e86d 100644 --- a/src/js/composer/commands/simulateCommands.js +++ b/src/js/composer/commands/simulateCommands.js @@ -110,41 +110,68 @@ export const simulateCommands = { ], }, { - value: "utools.simulateMouseClick", + value: "quickcomposer.simulate.mouseClick", label: "鼠标点击", config: [ { - label: "X坐标(留空则原地点击)", - icon: "drag_handle", - component: "NumberInput", - min: 0, - step: 10, - width: 6, + component: "ButtonGroup", + options: [ + { + label: "单击", + value: "Click", + }, + { + label: "右击", + value: "RightClick", + }, + { + label: "双击", + value: "DoubleClick", + }, + ], + defaultValue: "Click", + width: 12, }, { - label: "Y坐标(留空则原地点击)", - icon: "drag_handle", - component: "NumberInput", - min: 0, - step: 10, - width: 6, - }, - ], - subCommands: [ - { - label: "单击", - value: "utools.simulateMouseClick", - icon: "mouse", - }, - { - label: "右击", - value: "utools.simulateMouseRightClick", - icon: "mouse", - }, - { - label: "双击", - value: "utools.simulateMouseDoubleClick", - icon: "mouse", + component: "OptionEditor", + options: { + x: { + label: "X坐标", + icon: "drag_handle", + component: "NumberInput", + min: 0, + step: 10, + width: 6, + placeholder: "XY任意留空原地点击", + }, + y: { + label: "Y坐标", + icon: "drag_handle", + component: "NumberInput", + min: 0, + step: 10, + width: 6, + placeholder: "XY任意留空原地点击", + }, + count: { + label: "点击次数", + component: "NumberInput", + min: 1, + step: 1, + width: 6, + defaultValue: 1, + }, + interval: { + label: "点击间隔(毫秒)", + component: "NumberInput", + min: 0, + step: 100, + width: 6, + }, + }, + defaultValue: { + count: 1, + }, }, ], },