我正在将Alt+F4映射到ESC,这样我只需按escape就可以关闭窗口。然而,有两个窗口我需要实际使用ESC。因此,当这两个窗口中的任何一个处于活动状态时,我希望能够在不关闭窗口的情况下按ESC。实现这一点最简单的方法是什么?当我只是排除一个活动窗口时,我的脚本可以工作,但当两个窗口中的任何一个都处于活动状态时,我都需要工作。
这是我尝试的代码:
GroupAdd, ESC, Untitled - Notepad
GroupAdd, ESC,
#IfWinNotActive, ahk_group, ESC
Escape::!F4
Return
这是只适用于一个窗口的代码:
;#IfWinNotActive, Untitled - Notepad
;Escape::!F4
;Return
更新:应该这样做吗?
SetTitleMatchMode, 2
SetTitleMatchMode, 2
#IfWinNotActive, Untitled - Notepad
#IfWinNotActive, Document 1 - Microsoft Word
Escape::!F4
Return
在ahk_group
之后的#IfWinNotActive
行中有一个额外的逗号
尝试以下操作:
GroupAdd, ESC, Untitled - Notepad
; Add more windows to the group if necessary
#IfWinNotActive, ahk_group ESC
Escape::!F4
Return
尝试使用SetTitleMatchMode
。
http://www.autohotkey.com/docs/commands/SetTitleMatchMode.htm
2:窗口的标题可以包含WinTitle火柴
然后你可以这样做(默认情况下区分大小写):
settitlematchmode, 2
#IfWinNotActive, Untitled -
试试这个:
首先,不能在同一个脚本中两次重新映射同一个键。
此命令会影响所有窗口化命令的行为,例如。IfWinExist和WinActivate。
第二,你这样堆叠行:
#IfWinNotActive, Untitled - Notepad
#IfWinNotActive, Document 1 - Microsoft Word
你是说,如果win1不活动,那么如果win2不活动。
试试这个:
settitlematchmode, 2
app1 := winexist("other app")
app2 := winexist("Untitled - Notepad")
if(app1 || app2) ;the || means OR. you can use && for AND.
Escape::!F4 ;you can only map a particular key one time per script
或者这个,更符合你的方法:
settitlematchmode, 2
GroupAdd, ESC, Untitled - Notepad
GroupAdd, ESC, My other window
IfWinNotActive, ahk_group ESC
Escape::!F4
Return
这对我有效:
1:在你的脚本顶部写下这个(在第一个热键之前):
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode, Regex
2:然后可以使用非运算符!
:
if !(WinActive("ahk_class Notepad") or WinActive("ahk_class Calculator")) {
...
}
信用