GamerZG

Check Active Window

7 posts in this topic

#1 ·  Posted

hi everyone...

i wondering is it possible make func inside script to check window title and show GUI only when that window is active. if not active then script not show anything.

let me explain more: example... if u make some script binded to notepad (ONLY), script show fixed notification on screen (with info about hotkeys) and if u switch window (ALT+TAB or clicked in taskbar)  then that notification should be gone until u switch back to notepad.

i hope i explained ok... sorry about my english... is not perfect...

Share this post


Link to post
Share on other sites



#2 ·  Posted

Hi @GamerZG.

I think _WinAPI_SetWinEventHook is what you are looking for.

With the $EVENT_SYSTEM_FOREGROUND and/or $EVENT_SYSTEM_SWITCHSTART

A example in c# from stackoverflow: Detect active window changed using C# without polling

 

Hope this helps.

Share this post


Link to post
Share on other sites

#4 ·  Posted

15 minutes ago, LerN said:

Maybe:

While 1
if not WinExists("New Text Document (2).txt - Notepad") Then
    ContinueLoop
Else
    ; your code here
    msgbox(0,"","Found notepad")
    ExitLoop
EndIf
WEnd

 

i would suggest adding Sleep to avoid high CPU usage

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

thx @LerN and @genius257 :)

ill try WinAPI_SetWinEventHook but it seems lil complicated for me now...

meanwhile i made some simple code with check every 1 sec if window is active... thats alternative for now...

#include <AutoItConstants.au3>

Local $TITLE = "Notepad"

While 1
    Notification1()
    If not WinActive ($TITLE) Then
        SplashOff()
    EndIf
    If not WinExists ($TITLE) Then
        Exit 0
    EndIf
    Sleep(1000)
WEnd

Func Notification1()
    SplashImageOn("Splash Screen", "notif1.bmp", 300, 150, 1000, 0, $DLG_NOTITLE)
EndFunc

now i trying to figure how to put notification splash screen in top-right corner (or middle-right) depending on resolution

Edited by GamerZG

Share this post


Link to post
Share on other sites

#7 ·  Posted

i found solution for resolution... :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now