多线程找图:原理与使用说明
本示例演示如何使用 AutoHotkey L 版本(支持原生多线程的 AHK 分支)实现「多张图片批量找图」。核心思路是借助 pic_search_mutithread 库,把每张待查找图片分派到独立线程并行匹配,从而大幅提升在屏幕大范围内同时查找多张目标图像的效率与响应速度。
使用流程:先用 FileSelectFile 一次性选择多张 BMP 图片(路径与图片名不能含下划线);随后按提示按住左键拖选查找区域(GetRange 返回 x/y/w/h);脚本会在该选区内并行执行 pic_search_debug 逐一比对,最终通过 obj2json 输出每张图片的查找坐标与耗时。
关键参数:thresh 为匹配相似度阈值(示例取 100),值越低匹配越严格;CoordMode, Mouse, Screen 保证拖选区域使用屏幕坐标。
AHK v1/v2 说明:本文代码为 AHK v1(L 版)语法。迁移到 AutoHotkey v2 时需注意:FileSelectFile 返回对象而非字符串、StringTrimRight 改用 RTrim()、%var% 拼接改为表达式写法;并且 v2 默认即支持多线程并发,部分场景可直接用并发替代此库。
链接:https://pan.baidu.com/s/1RaUghMhz1p0InQL4rycRng
提取码:9xjf
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen ; 把 ToolTips 放置在相对于屏幕坐标的位置.
#include <pic_search_mutithread>
MsgBox,选择需要查找的图片,bmp格式
FileSelectFile, files, M3 ; M3 = 选择多个现有文件,路径和图片名字不能有"_"".
if (files = "")
{
MsgBox, The user pressed cancel.
return
}
string_path := ""
Loop, parse, files, `n
{
if (A_Index = 1)
{
root_path := A_LoopField
}
else
{
string_path := root_path . "" . A_LoopField . "*" . string_path
}
}
StringTrimRight, string_path, string_path, 1
MsgBox,% string_path
MsgBox,按住左键拖动选取查找范围
Sleep,200
MsgBox, 4096,, % GetRange(x,y,w,h) "范围:" x "," y "," w "," h
picPath := string_path
x1 := x
y1 := y
x2 := x+w
y2 := y+h
thresh := 100
obj := {}
pic_search_debug(picPath, x1, y1, x2, y2, time, obj, thresh)
MsgBox,% obj2json(obj)
return


先试一下
你好 我想問下ahk怎麼實現後台取色
下载来试试
厉害了 我的哥
试了一下 好用
pic_search_debug(picPath, x1, y1, x2, y2, time, obj, thresh)
正式使用的时候,改用pic_search(picPath, x1, y1, x2, y2, time, obj, thresh)