使用热键或替换后,AHK 脚本循环不起作用

问题描述 投票:0回答:1

使用此代码:

Loop
{
    WinWait, Untitled - Notepad
    WinClose, Untitled - Notepad
}

我想自动关闭所有新的记事本窗口。

然后我想添加一个键盘快捷键来退出AHK脚本:

Esc::ExitApp

但是当我添加

Esc::ExitApp
时,循环似乎不起作用,并且在代码仍在运行时记事本窗口不会自动关闭:

Esc::ExitApp  ; ==> this line is causing the loop to malfunction and not work as expected

Loop
{
    WinWait, Untitled - Notepad
    WinClose, Untitled - Notepad
}

为什么会发生这种情况以及如何使其按预期工作?!

autohotkey
1个回答
0
投票

return之后的未标记代码无法访问并且永远不会执行。

热键

Esc::ExitApp  

是一个单行热键,具有隐含的返回值。

在这种情况下,您可以使用 If 语句来使循环工作:

Loop
{
    If WinExist("Untitled - Notepad")
        WinClose
    If GetKeyState("Esc","P")
        ExitApp
}

不幸的是,autohotkey 帮助网站目前已停止服务,因此我无法附加任何超链接。

© www.soinside.com 2019 - 2024. All rights reserved.