Sleep()
函数在按按钮时会出现问题。
我有一个If循环,在每次鼠标移动/点击之间随机延迟(最多10秒)。然而,当调用Sleep()
函数时,脚本停止响应其用户界面上的关闭和停止按钮的点击:
#cs ----------------------------------------------------------------------------
Author: JesterRM
Website: N/A
#ce ----------------------------------------------------------------------------
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
;Comments On Information
;Set Mouse Position - MouseMove ( x, y)
;Mouse Click At Current Position - MouseClick ("Button")
;Wait Between Each Click Local $hTimer = TimerInit()>insert Link Break< Sleep(TIME)
;Random Sleep Time Sleep(Random(1000, 10000, 1)) = Random Sleep between 1 and 10 seconds
Opt('MustDeclareVars', 1)
MainGUI()
Func MainGUI()
Local $Button1, $Button2, $Button3, $msg, $count, $OBJECT, $OBJECT_CTRL, $hTimer
Global $count, $OBJECT, $OBJECT_CTRL
$count = 0
GUICreate("FREE KaW Bot V0.01", 1000, 650)
; Button Position and Names
Opt("GUICoordMode", 2)
$Button1 = GUICtrlCreateButton("Start", 370, 30, 100)
$Button2 = GUICtrlCreateButton("Stop", 10, -1, 100)
$Button3 = GUICtrlCreateButton("Close", 10, -1, 100)
;Create Internet Explorer in Window
$OBJECT = ObjCreate("Shell.Explorer.2")
$OBJECT_CTRL = GUICtrlCreateObj($OBJECT, -650, 20, 900, 550)
GUISetState()
_IECreateEmbedded()
_IENavigate($OBJECT, "http://www.kingdomsatwar.com/play/")
GUISetState()
; Run the GUI until the window is closed
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
; Button PopUp Messages
; Start The Bot
Case $msg = $Button1
MsgBox(0, 'Start', 'Starting Bot in 10 Seconds after PopUp Closes')
Sleep(10000)
$count = 1
If $count = 1 Then
Do
MouseMove(800, 100)
; Begin The Timer and Store The Handle in a Variable
Local $hTimer = TimerInit()
; Sleep For 3 Seconds
Sleep(Random(1000, 7000, 1))
Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff.
MsgBox($MB_SYSTEMMODAL, "Time Difference", $fDiff)
MouseMove(200, 453)
; Begin The Timer and Store The Handle in a Variable
Local $hTimer = TimerInit()
; Sleep For 3 Seconds
Sleep(Random(1000, 7000, 1))
Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff.
MsgBox($MB_SYSTEMMODAL, "Time Difference", $fDiff)
Until $count = 0
Else
MsgBox(0, 'Stop', 'Stopping Bot')
EndIf
; Stop The Bot
Case $msg = $Button2
MsgBox(0, 'Stop', 'Stopping Bot')
$count = 0
; Close The Bot
Case $msg = $Button3
MsgBox(0, 'Close', 'Closing Bot')
Exit
EndSelect
WEnd
EndFunc
我该如何解决这个问题?