2011-11-05 133 views
3

我可以用什麼函數暫停AutoIt中的腳本?在AutoIt中以編程方式暫停腳本?

我知道我可以使用睡眠是這樣的:

Func TogglePause() 
    $Paused = NOT $Paused 
    While $Paused 
     sleep(100) 
     ToolTip('Script is "Paused"',0,0) 
    WEnd 
    ToolTip("") 
EndFunc 

但有已在AutoIt中已實施暫停功能?

+3

我不明白你期望從內置的暫停功能。在AutoIt中,睡眠功能是暫停功能,可以持續一段時間。在一個循環中,它永遠有效。還有什麼應該暫停功能呢? –

回答

3

睡眠已經是AutoIt中的「暫停」功能。

暫停腳本的唯一方法是在調試模式下單擊trayicon。

2

您可以隨時使用以下方法。我認爲這是最高效的。

HotKeySet("{F8}", "StartScript") 

While 1 
While $script = True 
MAIN SCRIPT HERE 
    WEnd 
WEnd 

Func StartScript() ; Functions are normally placed last, making it easier to browse the code. 

    If $script = False Then 
     $script = True 
     ToolTip("Runing|Press F8 to Stop",200,100,"Script Name",1,2) 
     Sleep(2000) 
     ToolTip("") 
    Else 
     $script = False 
     ToolTip("Stoped|Press F8 to Start",200,100,"Script Name",1,2) 
     Sleep(2000) 
     ToolTip("") 
    EndIf 
EndFunc ; ==> StartScript 
2

我一直使用熱鍵和函數來暫停我的腳本。看看下面的例子!

; Create a hot key. I'm using the "Pause/Break" key typically located near the number pad on the keyboard. The keycode for this key is simply "{PAUSE}" 
HotKeySet("{PAUSE}", "togglePause") 

; Create a Boolean (True of False variable) to tell your program whether or not your program is paused or unpaused. Set it equal to 'False' so the script is running by default. 
global $isPaused = False 

; Create the togglePause function to stop/start the script 
Func togglePause() 
    ; When this function is initiated, the code on the next line 'toggles' the variable to True/False. If the script is unpaused (the $isPaused variable is set to 'False') then the next line will change it to 'True' and vice versa. 
    $isPaused = NOT $isPaused 
    ; Create a while loop to stall the program 
    ; The line below is the same thing as "While $isPaused == True" 
    While $isPaused 
     ; This code will run constantly until the $isPaused variable is set to 'True'. To make the script do nothing, simply add a sleep command. 
     Sleep(100) 
    WEnd 
EndFunc 

這種方法是去簡單地調用「togglePause,因爲它可以通過按一個熱鍵(在這種情況下,暫停/休息鍵)或程序來完成可通過編程方式暫停一個很好的方式'功能。

例如:

; Create a hot key. I'm using the "Pause/Break" key typically located near the number pad on the keyboard. The keycode for this key is simply "{PAUSE}" 
HotKeySet("{PAUSE}", "togglePause") 

; Create a Boolean (True of False variable) to tell your program whether or not your program is paused or unpaused. Set it equal to 'False' so the script is running by default. 
global $isPaused = False 

MsgBox(0,"Unpaused", "You are able to see this because the program is unpaused!") 

; PRETEND LIKE THERE IS A BUNCH OF CODE HERE! 

MsgBox(0,"Pausing", "The script will automatically be paused once this dialog closes. Press the pause/break key to unpause!") 
togglePause() 
Sleep(500) 
MsgBox(0,"Ta-Da!", "The script has been manually unpaused!") 


; Create the togglePause function to stop/start the script 
Func togglePause() 
    ; When this function is initiated, the code on the next line 'toggles' the variable to True/False. If the script is unpaused (the $isPaused variable is set to 'False') then the next line will change it to 'True' and vice versa. 
    $isPaused = NOT $isPaused 
    ; Create a while loop to stall the program 
    ; The line below is the same thing as "While $isPaused == True" 
    While $isPaused 
     ; This code will run constantly until the $isPaused variable is set to 'True'. To make the script do nothing, simply add a sleep command. 
     Sleep(100) 
    WEnd 
EndFunc 

我希望這回答了你的問題!如果您有任何疑問,請發表評論我的帖子,我會盡我所能來回答它!