fix: 点击脚本声明DPI感知避免物理坐标被二次缩放; 缩放兜底返回实际框尺寸

This commit is contained in:
yu 2026-11-03 11:39:17 +08:00
parent 9868f5d51c
commit 68e16282de

View File

@ -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};