懒人精灵_一个公共通用的函数文件

[复制链接]
查看5626 | 回复21 | 2021-11-19 20:26:16 | 显示全部楼层 |阅读模式
基于"学习APP"公共通用的函数代码:
  1. -- 公共函数文件
  2. function FindStr(x1,y1,x2,y2,name_str)
  3.     --- 找到字符信息并单击该字符坐标
  4.     --- 使用ocrEx本地神经进行文字数字信息查找
  5.     --- FindStr(左上角x坐标,左上角y坐标,右下角x坐标,右下角y坐标,查找的名称)
  6.    
  7.     local res = ocrEx(x1,y1,x2,y2)        -- 调用本地神经网络ocrEx函数
  8.     if res ~= nil then
  9.         
  10.         for i=1,#res do                 -- 遍历框选范围内的字符串信息
  11.             -- print('找字体并确认',res[i])
  12.             local ret = string.find(res[i].text,name_str,1)
  13.             if ret then
  14.                 print('找到'..name_str,res[i].l,res[i].t)
  15.                 --tap(res[i].l+numrandom,res[i].t+numrandom)
  16.                 --sleep(rnd(2000,2500))
  17.                 return math.tointeger(res[i].l),math.tointeger(res[i].t)
  18.             end
  19.             
  20.         end
  21.     end
  22.    
  23. end

  24. function GetPic(x1,y1,x2,y2,pic_name)
  25.     -- 识别图片
  26.     -- GetPic(左上角x坐标,左上角y坐标,右下角x坐标,右下角y坐标,图片名)
  27.     local x=-1 y=-1
  28.    
  29.     ret,x,y = findPic(x1,y1,x2,y2,pic_name..".png","101010",0.9)
  30.     return ret,x,y
  31. end

  32. function ClickNode(class_tab)
  33.     -- 获取一个节点信息
  34.     -- ClickNode(节点table)
  35.     local ret = nodeLib.findOne(class_tab,true)
  36.     if ret ~= nil then
  37.         --print(ret)
  38.         nodeLib.click(ret)
  39.         sleep(rnd(100,150)*10)
  40.         return true
  41.     else
  42.         return false
  43.     end
  44. end

  45. function FindAllNode(class_tab)
  46.     -- 找节点信息,返回节点table
  47.     -- FindAllNode(节点table)
  48.     local ret = nodeLib.findAll(class_tab,true)
  49.     if ret ~= nil then
  50.         --print(ret)
  51.         return ret
  52.     end
  53.    
  54. end

  55. function GetNodeText(node,str)
  56.     -- 遍历节点判断符合的字符串并点击该节点
  57.     -- GetNodeText(节点表,查找的字符串)
  58.     if node ~= nil then
  59.         for k,v in pairs(node) do
  60.             if string.find(v.text, str, 1)then
  61.                 nodeLib.click(v)
  62.                 sleep(rnd(100,150)*10)
  63.                 return true
  64.             end
  65.             
  66.         end
  67.     end
  68.    
  69. end
  70. function GetAllPics(x1,y1,x2,y2,picname)
  71.     -- 找多个图片,返回所有图片的坐标
  72.     -- GetAllPics(左上角x坐标,左上角y坐标,右下角x坐标,右下角y坐标,图片名)
  73.     local arr = findPicAllPoint(x1,y1,x2,y2,picname..".png",1)
  74.     if(arr ~=nil) then
  75.         return arr
  76.     end
  77. end

  78. function FindPic(x1,y1,x2,y2,pic_name)
  79.     -- 找单个图片,返回坐标
  80.     -- FindPic(左上角x坐标,左上角y坐标,右下角x坐标,右下角y坐标,图片名)
  81.     local ret,x,y = findPic(x1,y1,x2,y2,pic_name..".png","101010",2,0.95)
  82.    
  83.     return x,y
  84. end
  85. function GetNodeTime(class_tab)
  86.     -- 获取节点text里的时间 返回分钟数
  87.     -- GetNodeTime(节点表)
  88.     local ret = nodeLib.findOne(class_tab,false)
  89.    
  90.     if ret ~=nil then
  91.         local Time = splitStr(ret.text,":")
  92.         
  93.         return math.tointeger(Time[1])
  94.         
  95.     end
  96. end

  97. function GetAllNode(class_tab,findstrPop)
  98.     -- 获取匹配上的所有节点,匹配是否包含字符串,是就把这个节点赋值nil,返回节点table
  99.     -- GetAllNode(节点table,查找的字符串)
  100.     local ret = nodeLib.findAll(class_tab,true)
  101.     if ret ~= nil then
  102.         for k,v in pairs(ret) do
  103.             if string.find(v.text,findstrPop, 1) then
  104.                 ret[k] = nil
  105.             end
  106.         end
  107.         return ret
  108.     end
  109.    
  110.    
  111. end


  112. function Splitstring(strdata,str1)
  113.     -- 找查字符串是否包含子串
  114.     -- Splitstring(字符串,查找的字符串)
  115.     if string.find(strdata, str1, 1) then
  116.         
  117.         return true
  118.     else
  119.         return false
  120.     end
  121. end
  122. function Split(strdata,str1,str2,time)
  123.     -- 对字符串进行分割后获取整数型
  124.     -- Split(字符串,查找字符1,查找字符2,数字字符)
  125.     local strm = splitStr(strdata,str1)
  126.    
  127.     if string.find(strm[1], str2, 1) then
  128.         
  129.         return true
  130.     end
  131.    
  132.     if string.match(strm[1],"%d%d") >= time then
  133.         
  134.         return true
  135.     else
  136.         return false
  137.     end
  138.    
  139. end


  140. function GetParentClick(class_str)
  141.     -- 根据当前的节点信息获取父节点并点击
  142.     -- GetParentClick(节点table)
  143.    
  144.     local ret = nodeLib.findParentNode(class_str,true)
  145.     if ret ~= nil then
  146.         ret.level = 12
  147.         nodeLib.click(ret)
  148.     end
  149.     sleep(rnd(1500,2200))
  150. end

  151. function SleepTime(n1,n2)
  152.     -- 等待挂起脚本,设置两个数字之间的等待时间
  153.     -- SleepTime(数字2,数字2)
  154.     local rndTime = rnd(n1*60,n2*60)
  155.     print(string.format("需要等待 %s 分钟",rndTime/60))
  156.     for i=1,rndTime do
  157.         if i % 10 == 0then
  158.             print("倒计时时间:",rndTime-i,"秒")
  159.             
  160.         end
  161.         sleep(1000)
  162.     end
  163.    
  164. end

  165. function IfTwoNode(class_tab1,class_tab2,str1)
  166.     -- 判断两个节点text字符串是否一直
  167.     -- IfTwoNode(节点表1,节点表2,查找的字符串)
  168.     local ret1 = nodeLib.findOne(class_tab1,true)
  169.     local ret2 = nodeLib.findOne(class_tab2,true)
  170.     if ret1.text ~=nil and ret2.text ~=nil then
  171.         local currenttime = splitStr(ret1.text,str1)
  172.         local totaltime = splitStr(ret2.text,str1)
  173.         if ret1.text == ret2.text then
  174.             return true,nil
  175.         else
  176.             return false,totaltime[1]-currenttime[1]
  177.         end
  178.     end
  179. end

  180. function FindNode(class_tab)
  181.     -- 找查节点 找到返回节点表 ,一直找,直到找到才退出
  182.     -- FindNode(节点表)
  183.     while true do
  184.         local ret = nodeLib.findOne(class_tab,true)
  185.         if ret ~= nil then
  186.             return ret
  187.         end
  188.     end
  189.    
  190. end

  191. function CloseRun(time)
  192.     -- 等待五分钟后关闭脚本
  193.     -- CloseRun(时间分钟)
  194.     for i=1,rnd(time*60) do
  195.         sleep(1000)
  196.     end
  197.     return exitScript()
  198. end
复制代码
11.png



回复

使用道具 举报

肉肉爱破解 | 2021-11-20 00:24:04 | 显示全部楼层
哈哈哈哈哈昂,
回复

使用道具 举报

lipeiwen_3 | 2021-11-20 08:19:40 | 显示全部楼层
顶一个 牛逼了
回复

使用道具 举报

zj1997 | 2021-11-21 08:04:48 | 显示全部楼层
感谢大佬分享
回复

使用道具 举报

lipeiwen_3 | 2021-11-21 10:56:19 | 显示全部楼层
支持一下 啊哈哈哈哈哈
回复

使用道具 举报

jayxtxk | 2021-11-22 08:51:16 | 显示全部楼层
还是经常用到的
回复

使用道具 举报

jayxtxk | 2021-11-22 09:08:53 | 显示全部楼层

感谢大佬分享
回复

使用道具 举报

cyc262 | 2021-11-22 09:21:45 | 显示全部楼层
谢谢分享
好★天
好★天
学★向
习★
回复

使用道具 举报

xywl | 2021-11-22 21:03:39 | 显示全部楼层


感谢大佬分享
回复

使用道具 举报

yyyzzz | 2021-11-23 11:00:15 | 显示全部楼层
感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则