1
votes

I am using AutoHotKeys to test if a window is active along with an expression. I don't seem to be able to get it to work. I am assigning the expression to a variable and then testing for ifWinActive and the variable. AutoHotKeys doesn't seem to be able to evaluate the expression correctly. This is my script:

^W::
;hotkey always fires

done = false


SetTimer, CheckPopups, 10000    ; check every 10 seconds for window
CheckPopups:    
this := (done != true)

#IfWinActive "Volume Spike - Down" and this 
{
;specific lines only when active window is true and done is false
msgbox hello
done := true

}
IfWinNotActive Volume Spike - Down
{
done = false
}

When I launch the script and the window is not active, it shows the message box Hello. Then 10 seconds later it shows it again. It should only show the message box if the window is active and done = false. Any idea what I am doing wrong?

1
it should be either msgbox % this or msgbox %this%phil294
Thanks. I fixed that part.user3229570
I changed it to IfWinActive from #IfWinActive and it seems to workuser3229570

1 Answers

2
votes

You're using #IfWinActive, which is a directive used to create conditional hotkeys. You should use IfWinActive instead.

You can also use the function version, WinActive() inside your if-clause. It makes it look a little cleaner in my opinion.

Here's a short example:

#Persistent

done := false
SetTimer, CheckPopups, 1000 ; Check every second for window
return

CheckPopups:

    if ( WinActive("Volume Spike - Down") ) and (!done) {
        msgBox, Hello
        done := true
    } else {
        done := false
    }

return