在 AutoIt 中以编程方式暂停脚本?

发布于 2024-12-13 16:40:43 字数 339 浏览 5 评论 0原文

我可以使用什么函数来暂停 AutoIt 中的脚本?

我知道我可以像这样使用 sleep:

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

但是 AutoIt 中是否已经实现了暂停功能?

What function can I use to pause a script in AutoIt?

I know I can use sleep like this:

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

But is there a function for pause which has been implemented in AutoIt?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷路的信 2024-12-20 16:40:43

我总是使用热键和函数来暂停我的脚本:

; 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

I always used a hotkey and function to pause my script:

; 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

This can be done by pressing a hotkey (in this case Pause/Break) or by simply calling togglePause(). Example:

; 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
樱&纷飞 2024-12-20 16:40:43

睡眠已经是 AutoIt 中的“暂停”功能。

暂停脚本的唯一其他方法是在调试模式下单击托盘图标。

Sleep already is the "pause"-function in AutoIt.

The only other method to pause the script is to click the trayicon in debug mode.

一抹苦笑 2024-12-20 16:40:43

您始终可以使用以下方法。我认为这是最有效率的。

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

You could always use the following method. I think it's the most efficient.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文