My code does the following:
When a google.com window becomes active, it will show you a simple GUI.
Then, if you switch to another tab, the GUI will be hidden.[1]
[1]. Note, that it works as well for the tabs opened in another browser window. For example, you may have 2 browser windows opened - the first window with google.com
and apple.com
, and the second window with amazon.com
. You can click apple.com
tab as well as amazon.com
tab, and in both cases the GUI will be hidden. Then, if you click google.com
tab, the GUI will be shown again.
The problem is, that I cannot figure out how to force the GUI to be hidden when the window (which contains google.com
tab) is minimized. (And also, I cannot get rid of feeling that there are another errors, that are not visible while testing, but actually exist).
To sum this up, what I want is this:
As soon as a non-google window or tab is clicked/activated (excluding the AHK Gui) the Gui should be hidden and as soon as any google-window/tab is clicked/activated the Gui should be shown.
Here is my code:
#Persistent
SetTimer, Show_Gui, 300
Return
Show_Gui:
IfWinNotActive, foo
IfWinNotActive, Google
{
Gui, Destroy
Return
}
; Otherwise:
SetTimer, Show_Gui, Off
Gui, Add, Button, w200 h25 gTest1, button 1
Gui, Add, Button, w200 h25 gTest2, button 2
Gui, Show,, foo
WinWaitNotActive, foo
WinWaitNotActive, Google
SetTimer, Show_Gui, On
Return
Test1:
; do something
Return
Test2:
; do something
Return
Edit. Here is the code as discussed in comments to Forivin's post. It is not part of the actual question.
#Persistent
Gui, Add, Button, w200 h25 gTest1, button 1
Gui, Add, Button, w200 h25 gTest2, button 2
GroupAdd, myGroup, Google
GroupAdd, myGroup, foo
WinWaitActive, Google
Gui, Show,, foo
SetTimer, Gui_Visibility_Handler, 300
Return
Gui_Visibility_Handler:
WinGet, googleWinState, MinMax, Google
If (googleWinState = -1 || !WinExist("Google")) ;if window minimized or not existent
{
Gui, Hide
If (googleWinState = -1) ;workaround for a bug where windows thinks
Send, !{Esc} ;that the minimized window is active
WinWaitActive, Google
Gui, Show
Return
}
IfWinActive, Google
{
Gui, Show
Return
}
IfWinNotActive, ahk_group MyGroup
{
Gui, Hide
Return
}
Return
Test1:
;do something
Return
Test2:
;do something
Return