Another option is below. This behavior can be replicated with a
Hotkey command if needed, but you do not actually need it. You can change the directives to get whatever effect you want.
Code: Select all
#Requires AutoHotkey v1.1.33.11
winTitle := "ahk_exe Notepad.exe"
!^F10::
on := True
SoundBeep 1500
Return
F10::MsgBox 64, Information, 333333333333333333
#If on
F10::MsgBox 48, Warning, Precedence
#If WinActive(winTitle)
F10::MsgBox 64, Information, NOT precedence
#If
From the documentation:
Like the #IfWin directives, #If is positional: it affects all hotkeys and hotstrings physically beneath it in the script. #If and #IfWin are also mutually exclusive; that is, only the most recent #If or #IfWin will be in effect. If more than one variant is eligible to fire, only the one closest to the top of the script will fire. The exception to this is the global variant (the one with no #IfWin criteria): It always has the lowest precedence; therefore, it will fire only if no other variant is eligible (this exception does not apply to hotstrings).
To apply only when the target window is active:
Code: Select all
#Requires AutoHotkey v1.1.33.11
winTitle := "ahk_exe Notepad.exe"
!^F10::
on := True
SoundBeep 1500
Return
F10::MsgBox 64, Information, 333333333333333333
#If WinActive(winTitle)
F10::
If on {
MsgBox 48, Warning, Precedence
} Else {
MsgBox 64, Information, NOT precedence
}
Return
#If
Code: Select all
#Requires AutoHotkey v1.1.33.11
winTitle := "ahk_exe Notepad.exe"
on := False
!^F10::
on := True
SoundBeep 1500
Return
F10::
Switch (WinActive(winTitle) > 0) on {
Case 11: MsgBox Both
Case 10: MsgBox Only WinActive
Default: MsgBox Not WinActive
}
Return