一个demo 包含函数定义, 鼠标动作, 键盘输入, 时间控制, 流程控制, 跳转. 以后可供参考
-
'搜索的视图大小。
-
STD_LEFT = 20
-
STD_TOP = 100
-
STD_RIGHT = 620
-
STD_BOTTOM = 1000
-
-
Function DoClick
-
LeftDown 1
-
Delay 20
-
LeftClick 1
-
Delay 20
-
LeftUp 1
-
Delay 1
-
LeftUp 1
-
Delay 1
-
End Function
-
-
Function CloseAGWindow
-
MoveTo 616, 8
-
Delay 500
-
LeftClick 1
-
LeftUp 1
-
End Function
-
-
Function LoadAGFromIM
-
CloseAGWindow
-
'==========以下是按键精灵录制的内容========== 需要把 99U 放置在屏幕右下角, 非自动隐藏状态。
-
iconRetry = 3
-
While (iconRetry > 0)
-
img = "C:\Users\ray\Desktop\AG_BMP\AppIco.bmp"
-
FindPic 1000, 990, 1200, 1020, img, 0.9, BmpPos(0), BmpPos(1)
-
If (BmpPos(0) >= 0) Then
-
iconRetry = 0
-
Else
-
Delay 1000
-
iconRetry = iconRetry -1
-
End If
-
Wend
-
-
If (BmpPos(0) <= 0) Then
-
BmpPos (0) = 1055
-
BmpPos(1) = 1008
-
End If
-
-
If (BmpPos(0) >= 0) Then
-
MoveTo BmpPos(0), BmpPos(1)
-
Delay 100
-
LeftDoubleClick 1
-
Delay 78
-
MoveTo 1017, 564
-
LeftClick 1
-
End If
-
-
MoveTo 1017, 564
-
LeftClick 1
-
-
'==========以上是按键精灵录制的内容==========
-
End Function
-
-
Function btnBackClick '返回按钮。
-
MoveTo 89,116
-
DoClick
-
End Function
-
-
Function ReloadApp ' 浏览器刷新菜单
-
MoveTo 79,62
-
DoClick
-
End Function
-
-
-
'全局, 根据图像列表, 找到第一个匹配的对象, 并返回坐标点。
-
Dim BmpList(100)
-
Dim BmpIdx '当前正在查找图像的位置 0 坐标开始
-
Dim BmpPos(2) '第一个找到的坐标位置。 X, Y
-
-
Function FindBmp(bmpPath)
-
img = "C:\Users\ray\Desktop\AG_BMP\"' & bmpPath & "bmp"
-
img = img & bmpPath
-
img = img & ".bmp"
-
isFileExist = Plugin.File.IsFileExist(img)
-
If isFileExist = True Then
-
FindPic STD_LEFT, STD_TOP, STD_RIGHT, STD_BOTTOM, img, 0.9, BmpPos(0), BmpPos(1)
-
Else
-
BmpPos(0) = -1
-
BmpPos(1) = -1
-
End If
-
-
FindBmp = BmpPos(0)
-
If (BmpPos(0) > 0) And (BmpPos(1) > 0) Then //得到确切的位置。即中心点坐标。
-
Set Bmp = CreateObject("WIA.ImageFile")
-
Bmp.LoadFile (img)
-
width = Bmp.Width
-
height = Bmp.Height
-
BmpPos(0) = BmpPos(0) + Round(width/2)
-
BmpPos(1) = BmpPos(1) + Round(height/2)
-
End If
-
End Function
-
-
'从 BmpList 中前 bmpCnt个中依次查找, 找到的内容进行反馈到 bmpInx 和 BmpPos中。
-
Dim BmpNamePrefix '图片前缀
-
Function LocateBmpFromList(BmpNameCnt) '图片个数
-
BmpList(0) = BmpNamePrefix
-
idx = 1
-
While idx < BmpNameCnt
-
img = BmpNamePrefix & "_" & (idx - 1)
-
BmpList(idx) = img
-
idx = idx + 1
-
Wend
-
-
idx = 0
-
While idx < BmpNameCnt
-
FindBmp (BmpList(idx))
-
If (BmpPos(0) > 0) And (BmpPos(1) > 0) Then
-
BmpIdx = idx
-
LocateBmpFromList = BmpIdx
-
Exit Function
-
End If
-
idx = idx + 1
-
Wend
-
-
BmpIdx = -1
-
End Function
-
-
MinSpan = 5
-
DefSpan = 10
-
sMinute = -10
-
eMinute = 0
-
spanMinute = 0
-
iNewDay = - 1
-
iTimeEscape = 0
-
iDoNothing = 0
-
sHour = 0 // reload per hour
-
-
Function InitVariant
-
If (iNewDay < 0) Then
-
iNewDay = Date
-
sMinute = -10
-
End If
-
End Function
-
-
Function CheckMinuteSpan
-
eMinute = Minute(Now)
-
If eMinute >= sMinute Then
-
spanMinute = eMinute - sMinute
-
Else
-
spanMinute = eMinute - sMinute + 60
-
End If
-
End Function
-
-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
DebugImgIndex = 0
-
' 主程序开始
-
Rem LOOP_START
-
-
eHour = Hour(Now)
-
If (eHour <> sHour) Then
-
sHour = eHour
-
'LoadAGFromIM '重新启动一个守护实例, 查看是否打工成功。
-
End If
-
-
Delay 1000
-
InitVariant
-
iDoNothing = iDoNothing + 1
-
-
'========= 首页, 领取金币按钮 ==========
-
BmpNamePrefix = "GetCoin"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1) ' 领取金币位置
-
DoClick
-
Goto LOOP_START
-
End If
-
-
'========= 一键获取 按钮 ==========
-
BmpNamePrefix = "btnOneKeyGet"
-
LocateBmpFromList(5)
-
-
If (BmpIdx >= 0) Then
-
CheckMinuteSpan
-
If (spanMinute <= MinSpan) Then
-
btnBackClick
-
Else
-
sMinute = Minute(Now)
-
MoveTo BmpPos(0), BmpPos(1)
-
DoClick
-
Delay 6000'等待倒计时结束
-
End If
-
End If
-
-
-
' 一键获取后出现的不理会和领取的按钮。
-
BmpNamePrefix = "btnGetit"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Delay 1000
-
'Goto LOOP_START
-
End If
-
-
' 一键获取后的关闭未处理事件。
-
BmpNamePrefix = "btnClose"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Delay 1000
-
'Goto LOOP_START
-
End If
-
'========= 一键获取后, 完成打工的“尚有未处理事件”的提示框 ==========
-
BmpNamePrefix = "btnOneKeyGetEvent"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Delay 1000
-
'Goto LOOP_START
-
End If
-
'========= 无人打工的界面 ==========
-
BmpNamePrefix = "AddSym"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Delay 3000
-
sMinute = Minute(Now)
-
'Goto LOOP_START
-
End If
-
-
'========= 新派遣打工 按钮 ==========
-
BmpNamePrefix = "StartWork"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
sMinute = Minute(Now)
-
MoveTo 300,940
-
DoClick
-
Delay 1000
-
'LoadAGFromIM '重新启动一个守护实例, 查看是否打工成功。
-
-
Goto LOOP_START
-
End If
-
-
'========= 首页, 派遣按钮 ==========
-
BmpNamePrefix = "btnStart"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
CheckMinuteSpan
-
If (spanMinute >= DefSpan) Then
-
MoveTo 212,941
-
DoClick
-
Delay 1000
-
End If
-
-
Goto LOOP_START
-
End If
-
-
'========= 生产按钮 ==========
-
BmpNamePrefix = "btnProduce"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Goto LOOP_START
-
End If
-
'====== MoreSee , repeat for more times doWorker action =====
-
BmpNamePrefix = "MoreWorker"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Goto LOOP_START
-
End If
-
-
'========= 重复登录按钮 ==========
-
BmpNamePrefix = "btnExit"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
'此时可能在手机端有操作, 那么冗余10分钟时间给手机端使用。
-
Delay 600000
-
MoveTo BmpPos(0), BmpPos(1)
-
DoClick
-
Goto LOOP_START
-
End If
-
-
'========= 个人中心页面/ 天使名*录页面 ==========
-
BmpNamePrefix = "selfcenter"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
btnBackClick
-
Goto LOOP_START
-
End If
-
BmpNamePrefix = "SomeBody"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
btnBackClick
-
Goto LOOP_START
-
End If
-
-
'========= 每日签到 ==========
-
BmpNamePrefix = "SigIn"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
Delay 1000
-
End If
-
-
BmpNamePrefix = "SigOK"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
BmpNamePrefix = "SigClose"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
MoveTo BmpPos(0),BmpPos(1)
-
DoClick
-
'LoadAGFromIM '重新启动一个守护实例, 查看是否打工成功。
-
Goto LOOP_START
-
End If
-
End If
-
-
-
-
'========= 如果到此, 判断是否在主页上。 ==========
-
BmpNamePrefix = "MainPage"
-
LocateBmpFromList(5)
-
If (BmpIdx >= 0) Then
-
inMainPage = 1
-
Else
-
inMainPage = 0
-
End If
-
-
If (inMainPage = 0) Then
-
iTimeEscape = iTimeEscape + 1
-
Else
-
iTimeEscape = 0
-
End If
-
-
If (iTimeEscape = 20) Then
-
'LoadAGFromIM
-
iTimeEscape = 0
-
ElseIf (iTimeEscape = 10) Then
-
ReloadApp
-
Else
-
If (iTimeEscape = 5) Then
-
btnBackClick
-
Delay 1000
-
End If
-
End If
-
-
-
'imgDebug = CStr(Month(Now)) & "-" & CStr(Day(Now)) & "_" & CStr(Hour(Now)) & "." & CStr(Minute(Now)) & "_" & CStr(DebugImgIndex) & ".bmp"
-
'imgDebug = "C:\Users\ray\Desktop\AG_BMP\ScreenShot\" & imgDebug
-
'Call Plugin.Pic.PrintScreen(0, 0, 600, 1000, imgDebug)
-
'DebugImgIndex = DebugImgIndex + 1
-
-
'随机点击' 存在某些弹出框, 例如每日签到等情况
-
If (iTimeEscape = 5 ) Then
-
rndPosX = 320
-
rndPosY = 300
-
-
While rndPosY < 900
-
MoveTo rndPosX, rndPosY
-
DoClick
-
Delay 10
-
rndPosY = rndPosY + 20
-
Wend
-
End If
-
-
-
阅读(3261) | 评论(0) | 转发(0) |