我在toggle
块之外有#IfWinActive
变量,但变量没有用#IfWinActive
块初始化。如何切换一组热键?
toggle := false
f12::
toggle:=!toggle
SendInput {F12}
return
#IfWinActive ahk_class Chrome_WidgetWin_1
;toggle := false ;this doesn't do anything either
if (toggle) {
^a::SendInput {HOME}
}
#IfWinActive
您可以尝试此代码。
; [^ = Ctrl] [+ = Shift] [! = Alt] [# = Win]
#SingleInstance Force
Mode := 0
GroupAdd, Browser, ahk_class Chrome_WidgetWin_1 ; Chrome or Iron
;GroupAdd, Browser, ahk_class IEFrame ; Internet Explorer
;GroupAdd, Browser, ahk_class MozillaWindowClass ; FireFox
;GroupAdd, Browser, ahk_class ApplicationFrameWindow ; Edge
f12::
mode:=!mode ;not! toggle
return
#If mode ; All hotkeys below this line will only work, if mode is true and Browser is active.
^a::
If WinActive("ahk_group Browser")
{
SendInput {HOME}
} else {
send ^a
mode := 0
}
return
q::
If WinActive("ahk_group Browser")
{
send 1
} else {
send q
mode := 0
}
return
w::
If WinActive("ahk_group Browser")
{
send 2
} else {
send w
mode := 0
}
return
#If