diff --git a/src/main/capabilities/vision.ts b/src/main/capabilities/vision.ts index 742dda6..45d918f 100644 --- a/src/main/capabilities/vision.ts +++ b/src/main/capabilities/vision.ts @@ -327,10 +327,7 @@ export async function findImage(templatePath: string, screenshotPath: string, ac const scaled = await resizeTemplate(template, scale); if (scaled.width > screen.width || scaled.height > screen.height) continue; const scaledBest = scanBest(screen, scaled, maximumDifference); - if (scaledBest) { - // 结果框用原模板尺寸描述(宽高仅供点击锚点计算,位置才是关键) - return { ...scaledBest, width: template.width, height: template.height }; - } + if (scaledBest) return scaledBest; } return null; } @@ -428,12 +425,16 @@ async function injectClick(x: number, y: number, clickKey: string, showTrack: bo await powershell(`Add-Type @' using System; using System.Runtime.InteropServices; public static class Mouse { + [DllImport("user32.dll")] public static extern bool SetProcessDpiAwarenessContext(IntPtr value); [DllImport("user32.dll")] public static extern bool SetCursorPos(int X, int Y); [DllImport("user32.dll")] public static extern bool GetCursorPos(out POINT p); [DllImport("user32.dll")] public static extern void mouse_event(uint f, uint x, uint y, uint d, UIntPtr e); public struct POINT { public int X; public int Y; } } '@; +# 传入的是物理像素坐标(与物理分辨率截图匹配所得), 必须声明 DPI 感知—— +# 否则进程被 DPI 虚拟化, 坐标再被系统放大一次, 点击成比例偏右下 +try { [void][Mouse]::SetProcessDpiAwarenessContext([IntPtr](-4)) } catch {}; $p = New-Object Mouse+POINT; [Mouse]::GetCursorPos([ref]$p) | Out-Null; ${move};