autojs怎样指定范围找字

autojs怎样指定范围找字,自带函数有全屏找字,没有区域找字,想知道怎样才能指定范围找字,有什么方法吗,大佬们,求指教

1.获取控件范围bounds(),然后比对

2

//这个条件用于限制选择器在某一个区域选择控件。例如要在屏幕上半部分寻找文本控件//TextView,代码为:
var w = className("TextView").boundsInside(0, 0, device.width, device.height / 2).findOne();
log(w.text());
//其中我们使用了device.width来获取屏幕宽度,device.height来获取屏幕高度。

3

UiSelector.boundsContains(left, top, right, buttom)
•	left {number} 范围左边缘与屏幕左边的距离
•	top {number} 范围上边缘与屏幕上边的距离
•	right {number} 范围右边缘与屏幕左边的距离
•	bottom {number} 范围下边缘与屏幕上边的距离
为当前选择器附加控件"bounds需要包含left, top, right, buttom构成的范围"的条件。
这个条件用于限制控件的范围必须包含所给定的范围。例如给定一个点(500, 300), 寻找在这个点上的可点击控件的代码为:
var w = boundsContains(500, 300, device.width - 500, device.height - 300).clickable().findOne();
w.click();

相关文档:https://hyb1996.github.io/AutoJs-Docs/#/widgetsBasedAutomation?id=uiselectorboundsleft-top-right-buttom

可看下对你是否有所帮助。

可以参考这篇文章:https://blog.csdn.net/snailuncle2/article/details/113875129

在 Auto.js 中,你可以使用文本识别的方法来指定范围找字。下面是一个简单的示例代码,演示了如何在屏幕指定范围内查找指定文字:


var targetText = "要查找的文字";
var searchRegion = [100, 200, 500, 400]; // [left, top, right, bottom],指定范围的左上角和右下角坐标

// 使用文本识别方法查找文字
var textObj = text(targetText).boundsInside(searchRegion[0], searchRegion[1], searchRegion[2], searchRegion[3]).findOne();
if (textObj) {
  // 找到了目标文字
  var foundText = textObj.text();
  var foundBounds = textObj.bounds();
  console.log("找到目标文字:", foundText);
  console.log("文字位置:", foundBounds);
} else {
  // 没有找到目标文字
  console.log("未找到目标文字:", targetText);
}

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632