在 AutoIt 中以编程方式暂停脚本?
Posted
技术标签:
【中文标题】在 AutoIt 中以编程方式暂停脚本?【英文标题】:Pause script programmatically in AutoIt? 【发布时间】:2011-12-22 11:44:15 【问题描述】:我可以使用什么函数来暂停AutoIt 中的脚本?
我知道我可以像这样使用睡眠:
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
但是 AutoIt 中是否已经实现了暂停功能?
【问题讨论】:
我不明白您对内置暂停功能的期望。在 AutoIt 中,睡眠功能是工作一段时间的暂停功能。在一个循环中,它永远有效。暂停功能还应该做什么? "我可以使用什么函数来暂停 AutoIt 中的脚本?"Sleep()
. “我知道我可以……但是 AutoIt 中是否有暂停功能?”Sleep()
。 How to Ask.
【参考方案1】:
我总是使用热键和函数来暂停我的脚本:
; 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
这可以通过按下热键(在本例中为 Pause/Break)或调用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!")
; 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
【讨论】:
【参考方案2】:睡眠已经是 AutoIt 中的“暂停”功能。
暂停脚本的唯一方法是在调试模式下单击托盘图标。
【讨论】:
【参考方案3】:您始终可以使用以下方法。我认为这是最有效的。
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
【讨论】:
以上是关于在 AutoIt 中以编程方式暂停脚本?的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Jenkins/Hudson 中以编程方式设置环境变量?