An excerpt from AHK doc:
How can a hotkey or hotstring be made exclusive to certain program(s)? In other words, I want a certain key to act as it normally does except when a specific window is active.
The preferred method is #IfWinActive. For example:
#IfWinActive, ahk_class Notepad ^a::MsgBox You pressed Control-A while Notepad is active.
This works fine, but the entire rest of the AHK script file is conditionally run only when Notepad is focused.
How do I end the #IfWinActive. Better yet, where is the documentation that explains what # followed by a thing means.
2 Answers
Directly, the wording is:
Like the
#IfWindirectives,#Ifis positional: it affects all hotkeys and hotstrings physically beneath it in the script.#Ifand#IfWinare also mutually exclusive; that is, only the most recent#Ifor#IfWinwill be in effect.To turn off context sensitivity, specify #If or any #IfWin directive but omit all the parameters. For example:
#If
So, to essentially put an end-if is to put an empty #If after the block previously handled by the opening #If statement which would have a condition.
I found more documentation that fully explains what's going on here.
This language does not use an endif. You just write #if with no args to specify the negative case.
Terrible language. ;) But, it actually makes sense. This is less expressive from a programming point of view, but since the script is a configuration, 99% of the time you do want to split the binds into equally mutually exclusive zones of the file.