1
votes

I have a simple autohotkeys macro to test if a window is active. If it's active, I want to do something but then stop until the window becomes inactive and then re-activated again.

The problem is my test for whether the window was previously inactive is not working. Here is my code:

^w::
;hotkey always fires


done = false

SetTimer, CheckPopups, 10000    ; check every 10 seconds for annoying popup

CheckPopups:


if ( WinActive("Volume Spike - Down") )  
{
;specific lines only when active window is true
msgbox (%done%)
if (!done) {
  msgbox hello
  done := true

 }
}

IfWinNotActive Volume Spike - Down
{
done = false
msgbox Not
}

Return

When this runs, I get the first message box indicating the state of done (which is false at the beginning). But (!done) does not evaluate to true and the second message box (hello) is not fired. Any idea what is wrong here?

1

1 Answers

2
votes

AutoHotkey conceives true / false-boolean expressions as 1 / 0. If I were you, I wouldn't use the former keywords at all.

But still, you can, you just have to change the initialisation to

done := false

(store expression). done = false is actually the same like done := "false" (string assignment). Afaik, you could also change it to

done = %false%