2017-01-29 28 views
-2

我目前在AutoIt中設置了一個程序。這是什麼寫成的代碼,以及一些注意事項,可能是有用的,回答我的問題:一旦在AutoIt中按下「Q」按鈕,我該如何讓程序停止?

;File with data is pw.txt 
$fh = FileOpen("pw.txt") 
;Loops 5 times, every time it loops $attempt should equal the next line of pw.txt 
For $i = 1 To 10 
$attempt = FileReadLine($fh) 
MouseClick("left");MouseClick("left",711,256) 
Sleep(700) 
Send($attempt);Enters whatever is in $attempt variable 
Sleep(700) 
Send("{enter}") 
Sleep(700) 
MouseClick("left") 
Sleep(700);Once first loop is finished, second loop begins. The only thing that is different is what is entered ($attempt) 
Next 
FileClose("pw.txt");After finished looping, file closes. 

對於這個問題的緣故,我設置了循環計數爲10,所以以後$ I = 10 (循環10次後),程序仍然有效,但不會執行任何操作。

我想讓它如此,以便如果用戶點擊鍵盤上的「Q」按鈕,我的程序將停止,並且不會執行其他操作(我不想完全關閉程序,只需停止循環) 。我希望循環在下一次運行程序時從1開始運行

例如,如果我在循環4上並按下「Q」按鈕,循環將停止,然後我應該能夠點擊「F5」按鈕再次運行我的程序,並且它將在迴路1上。

任何幫助將不勝感激!謝謝!

+1

查看HotKeySet – Richard

回答

0

你需要一個主循環,它允許一次又一次地運行你的定時循環。您還需要運行和停止定時循環的功能,通過熱鍵調用:

HotKeySet('q', '_stopLoop') 
HotKeySet('{F5}', '_runLoop') 
HotKeySet('^!e', '_exit') ; (Ctrl+Alt+e) required to stop the main loop 
Global $iLoopCounter 

; start your loop now 
_runLoop() 


; you need a main loop 
While True 
    Sleep(10) 
WEnd 

Func _exit() 
    Exit 
EndFunc 

Func _MyLoop() 
    While $iLoopCounter < 10 
     $iLoopCounter += 1 
     ; your loop code here 

     ;==================================== for demonstration 
     ConsoleWrite('$iLoopCounter: ' & $iLoopCounter & @CRLF) 
     Sleep(1000) 
     ;====================================================== 

    WEnd 
EndFunc 

Func _runLoop() 
    $iLoopCounter = 0 
    _MyLoop() 
EndFunc 

Func _stopLoop() 
    $iLoopCounter = 10 
EndFunc 
相關問題