I want multiple hotkeys to work only if certain window is active and if a variable is equal 1. Something like

#IfWinActive Game #if var==1 ; assuming it doesn't close ... #if

Is it possible to achieve it without putting if statement into every hotkey?


You can use the ordinary WinActive function instead of the #IfWinActive directive to combine the two conditions, like this:

#If WinActive("ahk_class Game") and var==1

(Note for context: my original answer was totally off-base, because I hadn't realized that the various directives in the #If family are mutually exclusive, so that you can't usefully nest them.)

  • Somehow hotkeys are active always when var==1. It doesn't matter which window is active. I've just tried it on ahk v1.1.22.07. Also reversing #IfWinActive and #If only makes it sensitive to which window is active and it ignores var. It seems like each #If(...) closes the previous. – rezon Oct 11 '15 at 18:49
  • That's what I get for not testing my assumptions. Editing the solution to something that actually works. – Aaron Harris Oct 11 '15 at 21:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.