Skip to content

armgit / axuse

Public Imported from GitHub
0

Accessibility-first browser & computer use for AI agents — one MCP server for every harness (Codex, Claude Code, OpenCode, Antigravity). Instruments the DOM/accessibility tree via CDP instead of screenshot loops: diffed snapshots, stable element refs, trusted input, typed errors. Zero dependencies

desktop: windows pointer event timing controls

soloratech1fc65db83513
diff --git a/src/desktop/index.js b/src/desktop/index.js
index c79b88d..9650493 100644
--- a/src/desktop/index.js
+++ b/src/desktop/index.js
@@ -48,6 +48,15 @@ function exactBase64Bytes(b64) {
return Buffer.byteLength(Buffer.from(b64, "base64"));
}
+/** Pointer-event pacing validation, mirroring the macOS driver's timing
+ * controls: 0–1000 ms between events, typed COMMAND_REJECTED otherwise. */
+function pointerInterval(value) {
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1000) {
+ throw new AxError(Codes.COMMAND_REJECTED, "interval_ms must be between 0 and 1000", { retry: "never" });
+ }
+ return value;
+}
+
/** Resident Windows driver: one PowerShell process, one op at a time. */
class WindowsDriver {
constructor() {
@@ -165,8 +174,11 @@ class WindowsDriver {
return { action_sent: "sent" };
}
- async click({ x, y, button = "left", double = false } = {}) {
- await this.check(this.op({ op: "click", x, y, button, double }));
+ async click({ x, y, button = "left", double = false, interval_ms = 0 } = {}) {
+ interval_ms = pointerInterval(interval_ms);
+ // interval_ms is slept inside the resident PS process between down and up,
+ // keeping the press a single atomic gesture (like the macOS JXA delay()).
+ await this.check(this.op({ op: "click", x, y, button, double, interval_ms }));
return { action_sent: "sent" };
}
@@ -227,14 +239,30 @@ class WindowsDriver {
return { action_sent: "sent", combo };
}
- /** Drag via move/down/move/up (interpolated like the browser actuator). */
- async drag({ from, to, steps = 12 } = {}) {
+ /** Drag via move/down/move/up (interpolated like the browser actuator).
+ * interval_ms paces the gesture — after the press, between interpolated
+ * moves, and before the release — mirroring the macOS timing controls.
+ * The steps × interval_ms budget keeps a paced drag bounded in time. */
+ async drag({ from, to, steps = 12, interval_ms = 0 } = {}) {
+ interval_ms = pointerInterval(interval_ms);
+ const requestedSteps = steps;
+ if (typeof requestedSteps !== "number" || !Number.isFinite(requestedSteps) || requestedSteps < 1) {
+ throw new AxError(Codes.COMMAND_REJECTED, "steps must be ≥ 1", { retry: "never" });
+ }
+ const count = Math.round(requestedSteps);
+ if (count < 1) throw new AxError(Codes.COMMAND_REJECTED, "steps must round to at least 1", { retry: "never" });
+ if (count * interval_ms > 12000) throw new AxError(Codes.COMMAND_REJECTED, "steps × interval_ms must be ≤ 12000", { retry: "never" });
+ if (count > 200) throw new AxError(Codes.COMMAND_REJECTED, "steps must be ≤ 200", { retry: "never" });
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
await this.move(from.x, from.y);
await this.down("left");
- for (let i = 1; i <= steps; i++) {
- const x = Math.round(from.x + ((to.x - from.x) * i) / steps);
- const y = Math.round(from.y + ((to.y - from.y) * i) / steps);
- await this.move(x, y);
+ if (interval_ms) await sleep(interval_ms);
+ for (let i = 1; i <= count; i++) {
+ await this.move(
+ Math.round(from.x + ((to.x - from.x) * i) / count),
+ Math.round(from.y + ((to.y - from.y) * i) / count),
+ );
+ if (interval_ms) await sleep(interval_ms);
}
await this.up("left");
return { action_sent: "sent" };
diff --git a/src/desktop/windows.ps1 b/src/desktop/windows.ps1
index 2fbbca1..4225638 100644
--- a/src/desktop/windows.ps1
+++ b/src/desktop/windows.ps1
@@ -70,15 +70,21 @@ public class AxWin {
m.dwFlags = down; Send((int)INPUT_MOUSE, m);
m.dwFlags = up; Send((int)INPUT_MOUSE, m);
}
- public static void ClickButton(string button, bool dbl) {
+ public static void PressPair(uint down, uint up, int intervalMs) {
+ MOUSEINPUT m = new MOUSEINPUT();
+ m.dwFlags = down; Send((int)INPUT_MOUSE, m);
+ if (intervalMs > 0) System.Threading.Thread.Sleep(intervalMs);
+ m.dwFlags = up; Send((int)INPUT_MOUSE, m);
+ }
+ public static void ClickButton(string button, bool dbl, int intervalMs) {
uint down, up;
switch (button) {
case "right": down = MOUSEEVENTF_RIGHTDOWN; up = MOUSEEVENTF_RIGHTUP; break;
case "middle": down = MOUSEEVENTF_MIDDLEDOWN; up = MOUSEEVENTF_MIDDLEUP; break;
default: down = MOUSEEVENTF_LEFTDOWN; up = MOUSEEVENTF_LEFTUP; break;
}
- Button(down, up);
- if (dbl) { System.Threading.Thread.Sleep(30); Button(down, up); }
+ PressPair(down, up, intervalMs);
+ if (dbl) { System.Threading.Thread.Sleep(Math.Max(30, intervalMs)); PressPair(down, up, intervalMs); }
}
public static void Wheel(int dx, int dy) {
if (dy != 0) {
@@ -177,7 +183,8 @@ function Invoke-Op($req) {
'move' { [void][AxWin]::SetCursorPos([int]$req.x, [int]$req.y); @{ ok = $true } }
'click' {
[void][AxWin]::SetCursorPos([int]$req.x, [int]$req.y)
- [AxWin]::ClickButton([string]$req.button, [bool]$req.double)
+ $interval = if ($null -ne $req.interval_ms) { [int]$req.interval_ms } else { 0 }
+ [AxWin]::ClickButton([string]$req.button, [bool]$req.double, $interval)
@{ ok = $true }
}
'down' {
diff --git a/src/mcp/manifest.js b/src/mcp/manifest.js
index 18541a9..0766720 100644
--- a/src/mcp/manifest.js
+++ b/src/mcp/manifest.js
@@ -119,7 +119,7 @@ export function desktopTools(driverAvailable, axCapable = false) {
x: { type: "number" }, y: { type: "number" },
button: { type: "string", enum: ["left", "right", "middle"] },
double: { type: "boolean" },
- interval_ms: { type: "number", minimum: 0, maximum: 1000, description: "macOS: delay between pointer events in milliseconds (default 0)." },
+ interval_ms: { type: "number", minimum: 0, maximum: 1000, description: "Delay between pointer events in milliseconds (default 0; macOS and Windows)." },
},
required: ["x", "y"], additionalProperties: false,
},
@@ -172,7 +172,7 @@ export function desktopTools(driverAvailable, axCapable = false) {
from: { type: "object", properties: { x: { type: "number" }, y: { type: "number" } }, required: ["x", "y"], additionalProperties: false },
to: { type: "object", properties: { x: { type: "number" }, y: { type: "number" } }, required: ["x", "y"], additionalProperties: false },
steps: { type: "integer", minimum: 1, maximum: 200, description: "Number of interpolated moves (default 12)." },
- interval_ms: { type: "number", minimum: 0, maximum: 1000, description: "macOS: delay between pointer events in milliseconds (default 0; steps × interval_ms ≤ 12000)." },
+ interval_ms: { type: "number", minimum: 0, maximum: 1000, description: "Delay between pointer events in milliseconds (default 0; macOS and Windows; steps × interval_ms ≤ 12000)." },
},
required: ["from", "to"],
additionalProperties: false,
diff --git a/test/desktop.test.js b/test/desktop.test.js
index aebbcbb..6b1d878 100644
--- a/test/desktop.test.js
+++ b/test/desktop.test.js
@@ -527,3 +527,32 @@ test("macOS pointer timing is inserted between events and validated", async () =
await assert.rejects(() => d.click({ x: 1, y: 2, interval_ms: -1 }), (e) => e.code === "COMMAND_REJECTED");
await assert.rejects(() => d.drag({ from: { x: 1, y: 2 }, to: { x: 3, y: 4 }, steps: 200, interval_ms: 100 }), (e) => e.code === "COMMAND_REJECTED");
});
+
+test("Windows pointer timing is passed through, paced and validated", { skip: !isWindows }, async (t) => {
+ // Passive: op() is stubbed so no input is synthesized; timing is asserted
+ // from the recorded op stream and the wall clock the sleeps account for.
+ const d = getDesktopDriver();
+ const calls = [];
+ const realOp = d.op.bind(d);
+ d.op = async (payload) => { calls.push(payload); return { ok: true }; };
+ t.after(() => { d.op = realOp; d.dispose(); });
+
+ await d.click({ x: 4, y: 5, interval_ms: 40 });
+ assert.equal(calls[0].op, "click");
+ assert.equal(calls[0].interval_ms, 40, "click interval_ms reaches the PS driver");
+
+ calls.length = 0;
+ const steps = 8, interval = 25;
+ const t0 = Date.now();
+ await d.drag({ from: { x: 100, y: 100 }, to: { x: 300, y: 200 }, steps, interval_ms: interval });
+ const elapsed = Date.now() - t0;
+ assert.deepEqual(calls.map((c) => c.op), ["move", "down", ...Array(steps).fill("move"), "up"]);
+ // 9 sleeps (after press + after each move) ≥ 8 × 25ms; sloppy-timer margin.
+ assert.ok(elapsed >= steps * interval, `drag elapsed ${elapsed}ms, expected ≥ ${steps * interval}ms of pacing`);
+
+ await assert.rejects(() => d.click({ x: 1, y: 2, interval_ms: -1 }), (e) => e.code === "COMMAND_REJECTED");
+ await assert.rejects(() => d.click({ x: 1, y: 2, interval_ms: 1001 }), (e) => e.code === "COMMAND_REJECTED");
+ await assert.rejects(() => d.drag({ from: { x: 1, y: 2 }, to: { x: 3, y: 4 }, steps: 0 }), (e) => e.code === "COMMAND_REJECTED");
+ await assert.rejects(() => d.drag({ from: { x: 1, y: 2 }, to: { x: 3, y: 4 }, steps: 201 }), (e) => e.code === "COMMAND_REJECTED");
+ await assert.rejects(() => d.drag({ from: { x: 1, y: 2 }, to: { x: 3, y: 4 }, steps: 200, interval_ms: 100 }), (e) => e.code === "COMMAND_REJECTED");
+});