如何解决Autohotkey-使用WinActive和Hotstring
我需要代码来在打开记事本时启用Hotstring并在关闭记事本时禁用Hotstring。因此,我在下面编写了代码,发现该代码有时会错过记事本打开的事件。我该如何解决?
while True
{
begin:
Sleep,1
;Untitled - Notepad
while not WinActive("Untitled - Notepad")
{
Sleep,1
if WinActive("Untitled - Notepad")
{
MsgBox WinActive
HotString("::hello","Hello World",On)
goto,begin
}
HotString("::hello",Off)
}
}
a::
ExitApp
解决方法
#Directive是用于此目的的,更具体地说是#IfWinActive
directive。
这是您的成品:
#IfWinActive,ahk_class Notepad
::hello::Hello World
#IfWinActive
为方便起见,使用ahk_class
。您可以详细了解here。
另外,也可以使用#IfWinActive,ahk_exe notepad.exe
。
或者,当然,普通的#IfWinActive,Untitled - Notepad
也可以使用,但是仅当您编辑名为“无标题”的文档时才可以。这就是为什么它不是一个好方法的原因。
AHKv1:
#If WinActive("ahk_class Notepad")
::hello::Hello World
#If
AHKv2:
#HotIf WinActive("ahk_class Notepad")
::hello::Hello World
#HotIf
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。