在一次呼叫:
瑞祥幽冥狼 大神比如鼠标要点击图片的 应用模板,找不到应用模板,就去找应用模板02或者应用模板03.(都是一张图 因为一张图稍微有点变化 按键精灵就找不到了)
Call 循环找图("应用模板"or"应用模板02"or"应用模板03" )
Function 循环找图(图片)
循环找图= False
StartTime = Now()
TracePrint "本次运行时间为: " & StartTime
MaxAttempts = 500// 查找多少次
AttemptCount = 0//计数器 (放在do的上方)
Do
FindPic 0,0,1920,1080,"Attachment:\"&图片&".bmp", 1,X,Y
If X > 0 And Y > 0 Then
MoveTo x, y
Delay 300
LeftClick 1
EndTime = Now()//计算运行时长
RunTime = DateDiff("s", StartTime, EndTime)// 计算秒数差
TracePrint "子程序===> ^_* 恭喜第 ( " & AttemptCount & " ) 次成功找到了: " & 图片 & ",共耗时:" & RunTime & "秒"
Delay 300
循环找图 = True
Exit Do //退出循环找图
Else
TracePrint "正在第 " & AttemptCount & " 次寻找图片: " & 图片
End If
AttemptCount = AttemptCount + 1
If AttemptCount >= MaxAttempts Then // 查找500次后退出 (放在End If 或者 Exit Do上方)
MessageBox " 很遗憾这是第 ( "&AttemptCount&" ) 次没找到 ( " &图片&" )这张图 脚本停止运行!"
EndScript//脚本停止运行
End If
Delay 300
Loop

End Function
下面的这个代码我会用,但是经常频繁使用这个代码脚本写的凌乱繁琐,没有上面的那个简介.
Call 模框()
Function 模框()//Function 是需要被调用的,如果不需要调用直接使用do loop
picpath=array("模块框","模块框1" )//这里添加多个图片的名字
模框 = False'开头声明False,找到等于true
StartTime = Now()//读取时间
TracePrint "本次运行时间为: " & StartTime
MaxAttempts = 10// 查找20次
AttemptCount = 0//计数器 (放在do的上方)
do
TracePrint ""
For i=0 to UBound( picpath)'图片数组下标不能和次数i混用,i=10退出,图片只有4
FindPic 0, 0, 1920, 1080, "Attachment:\"&picpath(i)&".bmp", 1, x, y'不要采用附件路径,存在BUG
If x > 0 Then
MoveTo x, y
Delay 300
LeftClick 1
EndTime = Now()//计算运行时长
RunTime = DateDiff("s", StartTime, EndTime)// 计算秒数差
TracePrint "" //只是为了美观查看显示记录
TracePrint " ^_* 恭喜第 ( " & AttemptCount & " ) 次成功找到了: " & picpath(i) & ",共耗时:" & RunTime & " 秒"
模框 = i'直接返回找到的下标
Exit Function
Else //否则
AttemptCount = AttemptCount + 1//计数器
TracePrint "很遗憾第( " & AttemptCount & " )次未能找到( " & picpath(i) & " )这张图,继续循环找图中.........."
End If
Next
Delay 300
loop
End Function