回答
在Hamibot中,如果你需要编写一个脚本来完成类似“抢ppmt大娃两个”的操作,你需要明确具体的操作目标。例如,你是想在游戏中快速选择或点击特定角色(如“大娃”),还是在某个网页/应用中执行自动化任务?
假设你是在做一个游戏自动化的场景,比如你要在屏幕中找到两个“大娃”的图像并点击它们,你可以使用images.findImage()
函数来定位图像的位置,并通过RootAutomator.tap()
来模拟点击。
以下是一个示例脚本,它会在屏幕上查找两个“大娃”的图像并点击它们:
// 文档地址 https://docs.hamibot.com/
var img = images.read("/sdcard/大图.png"); // 当前屏幕截图或其他大图
var template1 = images.read("/sdcard/大娃1.png"); // 第一个大娃的模板图片
var template2 = images.read("/sdcard/大娃2.png"); // 第二个大娃的模板图片
// 查找第一个大娃
var pos1 = images.findImage(img, template1, {
threshold: 0.9,
region: [0, 0, device.width, device.height]
});
// 查找第二个大娃
var pos2 = images.findImage(img, template2, {
threshold: 0.9,
region: [0, 0, device.width, device.height]
});
if (pos1) {
toastLog("找到第一个大娃,坐标:" + pos1.x + ", " + pos1.y);
var ra = new RootAutomator();
ra.tap(pos1.x, pos1.y, 1); // 点击第一个大娃
ra.exit();
}
if (pos2) {
toastLog("找到第二个大娃,坐标:" + pos2.x + ", " + pos2.y);
var ra = new RootAutomator();
ra.tap(pos2.x, pos2.y, 1); // 点击第二个大娃
ra.exit();
}
解释:
-
images.findImage()
:用于在大图img
中查找小图template
的位置。threshold
:设置匹配的相似度阈值(0~1),越接近1表示要求越精确。region
:指定搜索区域,这里我们设为整个屏幕[0, 0, device.width, device.height]
。
-
RootAutomator.tap(x, y, id)
:模拟点击指定坐标(x, y)
,id
表示单点触摸。 -
路径设置:确保你的图片路径是正确的,例如
/sdcard/大图.png
是当前屏幕截图的路径,而/sdcard/大娃1.png
和/sdcard/大娃2.png
是你要查找的角色图片。 -
权限问题:运行脚本之前,请确保已经授予 Hamibot 屏幕截图和无障碍服务权限。
注意事项:
- 如果你找不到任何匹配的图像,可能需要调整
threshold
值或者检查图片是否清晰、是否有遮挡。 - 对于复杂的动态界面,建议结合
images.grayscale()
或images.threshold()
预处理图像以提高匹配准确性。
如果你能提供更具体的场景(例如游戏名称或操作环境),我可以为你定制更详细的解决方案!
ℹ️ 本回答由 AI 生成,内容仅供参考