下载地址:http://m.pan38.com/download.php?code=RQEBET 提取码:6666
主脚本实现基于模板匹配的自动点击功能,包含UI界面和参数配置。增强版提供了多目标识别和区域限定搜索功能。使用时需要先截图保存模板图片,设置匹配阈值和点击间隔后即可运行。
"ui";
// 主界面布局
ui.layout(
);
// 全局变量
let running = false;
let templateImg = null;
let lastMatch = null;
// 选择模板图片
ui.selectImg.click(() => {
let img = images.pick();
if(img){
templateImg = images.copy(img);
ui.imgPath.setText(img.getPath().split("/").pop());
toast("模板图已加载");
}
});
// 开始运行
ui.start.click(() => {
if(!templateImg){
toast("请先选择模板图片");
return;
}
running = true;
let threshold = parseFloat(ui.threshold.getText()) || 0.8;
let interval = parseInt(ui.interval.getText()) || 1000;
let maxRetry = parseInt(ui.maxRetry.getText()) || 5;
threads.start(function(){
let retryCount = 0;
while(running && retryCount < maxRetry){
try{
let screenshot = captureScreen();
let match = images.findImage(screenshot, templateImg, {
threshold: threshold
});
if(match){
lastMatch = match;
click(match.x + match.width/2, match.y + match.height/2);
log("点击位置: " + match.x + "," + match.y);
retryCount = 0;
}else{
log("未找到匹配目标");
retryCount++;
}
sleep(interval);
}catch(e){
log("发生错误: " + e);
break;
}
}
if(retryCount >= maxRetry){
log("达到最大重试次数,自动停止");
}
running = false;
});
});
// 停止运行
ui.stop.click(() => {
running = false;
log("已停止运行");
});
// 日志输出
function log(msg){
ui.log.append(msg + "\n");
console.log(msg);
}
// 多点触控点击函数
function click(x, y){
let duration = 50 + random(0, 50);
press(x, y, duration);
}
// 脚本退出时释放资源
events.on("exit", () => {
if(templateImg){
templateImg.recycle();
}
});
// 扩展功能:支持同时识别多个目标
function multiClick(){
let targets = [
{name: "按钮1", img: images.read("/sdcard/target1.png")},
{name: "按钮2", img: images.read("/sdcard/target2.png")},
{name: "按钮3", img: images.read("/sdcard/target3.png")}
];
let screenshot = captureScreen();
targets.forEach(target => {
let match = images.findImage(screenshot, target.img, {threshold: 0.7});
if(match){
click(match.x, match.y);
console.log("已点击" + target.name);
}
});
// 释放图片资源
targets.forEach(target => target.img.recycle());
}
// 区域限定搜索
function regionFind(img, template, region){
let clip = images.clip(img, region.x, region.y, region.width, region.height);
let result = images.findImage(clip, template);
if(result){
result.x += region.x;
result.y += region.y;
}
clip.recycle();
return result;
}