4

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 2

4

Directly, the wording is:

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.

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.

2
  • Thanks for quoting the doc, making your answer better than mine. Have an accept!
    – Steven Lu
    Mar 20, 2020 at 4:43
  • Well, thanks to you for providing the link in the first place. It was confusing to me at first because this language is different from most indeed, so I had to really read the source to ensure I understood it properly. Mar 20, 2020 at 5:35
4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .