From 68e16282de049e406d595d7914cfdd5810b21aff Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Tue, 3 Nov 2026 11:39:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=82=B9=E5=87=BB=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=A3=B0=E6=98=8EDPI=E6=84=9F=E7=9F=A5=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E7=89=A9=E7=90=86=E5=9D=90=E6=A0=87=E8=A2=AB=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E7=BC=A9=E6=94=BE;=20=E7=BC=A9=E6=94=BE=E5=85=9C=E5=BA=95?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=AE=9E=E9=99=85=E6=A1=86=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/capabilities/vision.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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};