AHK, where is the end if? (e.g. #IfWinActive keybinds)

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 #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

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like