用按键精灵巧妙获取时间间隔
1、调取系统底层API
GetTickCount函数介绍:
GetTickCount返回(retrieve)从操作系统启动所经过(elapsed)的毫秒数,它的返回值是DWORD。
函数声明:
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
函数范例:计算当前时间和5秒后的时间差
// 获取当前时间
TheTime = GetTickCount()
// 延时 5 秒
Delay 5000
// 再次获取当前时间,计算时间差
TracePrint GetTickCount() - TheTime
运行结果:

2、获取时间间隔:函数DateDiff与函数GetTickCount()对比
DateDiff只能获取到最小单位为:秒的数值
GetTickCount()可以获取到最小单位为:毫秒的数值
有时候,脚本的成败往往就在毫秒之间!
范例:等图找图大神代码
来看看大神提供的等图找图代码段吧~~
//声明函数GetTickCount
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
//找出多张图(hsz.bmp、jsj.bmp、ie.bmp)中的其中一张
TracePrint 找多图("hsz.bmp|jsj.bmp|ie.bmp")
//延迟5000ms,等待图(hsz.bmp)
TracePrint 等图_毫秒("hsz.bmp",5000)
//延迟5000ms,等待多张图(hsz.bmp、jsj.bmp、ie.bmp)中的其中一张
TracePrint 等多图_毫秒("hsz.bmp|jsj.bmp|ie.bmp",5000)
Function 找多图_数组(图像列表)
找多图_数组 = 0
For i = 0 To UBound(图像列表)
FindPic 0, 0, Plugin.Sys.GetScRX - 1, Plugin.Sys.GetScRY - 1, "Attachment:\" & 图像列表(i), 1, intX, intY
If IntX >= 0 Then
找多图_数组 = i + 1
Exit For
End If
Next
End Function
Function 找多图(图像)
找多图 = 找多图_数组(split(图像,"|"))
End Function
Function 等图_毫秒(图片, 超时时间)// 利用两次 GetTickCount() 得到时间间隔(单位:毫秒)
等图_毫秒 = TRUE
开始时间 = GetTickCount()
Do
If GetTickCount() - 开始时间 > 超时时间 Then 等图_毫秒 = FALSE:Exit Do
FindPic 0, 0, Plugin.Sys.GetScRX - 1, Plugin.Sys.GetScRY - 1, "Attachment:\" & 图片, 1, intX, intY
Loop Until IntX >= 0
End Function
Function 等多图_毫秒(图片, 超时时间)// 利用两次 GetTickCount() 得到时间间隔(单位:毫秒)
开始时间 = GetTickCount()
Do
If GetTickCount() - 开始时间 > 超时时间 Then Exit Do
等多图_毫秒 = 找多图(图片)
Loop Until 等多图_毫秒
End Function
运行结果:
