Jump to content

Check Active Window


Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...