user3229570
user3229570

Reputation: 933

autohotkeys using ifwinactive with expression not working

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?

Upvotes: 1

Views: 828

Answers (1)

Sid
Sid

Reputation: 1719

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

Upvotes: 2

Related Questions