Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate a Script only if a specific Window is active?

Tags:

autohotkey

I have a problem with a Script which should just do the following: - If a specific Window becomes active - SetCapslockState, On - If the Windows lost focus - SetCapslockState, Off

I've tried:

#If WinActive("ahk_class blahblah")

SetCapslockState, On

and/or

#If !WinActive("ahk_class Chrome_WidgetWin_1")

SetCapslockState, Off

But it don't work.

Also I've tried:

WinWaitActive, (mytitleofwindow)
if ErrorLevel
{
SetCapslockState, On

return
}
else

It don't work either, else I would not ask for help here... hihihi

I hope someone can help me! :)

like image 561
LeChatNoir Avatar asked Oct 23 '25 19:10

LeChatNoir


1 Answers

The key is to combine WinWait[Not]Active with a Loop.

Loop {
    WinWaitActive, mytitleofwindow
    SetCapslockState, On
    WinWaitNotActive, mytitleofwindow
    SetCapslockState, Off
}
like image 183
Forivin Avatar answered Oct 26 '25 21:10

Forivin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!