AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Monitoring active window changes & settimer questions

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
pokercurious



Joined: 16 Dec 2007
Posts: 48

PostPosted: Tue Oct 07, 2008 12:24 am    Post subject: Monitoring active window changes & settimer questions Reply with quote

I'm writing a computer usage app along the lines of this

I'd prefer finer-grained tracking of the active window, so I came up with the following:

Code:
#Persistent

lastActiveWindow := currActiveWindow := WinExist("A")

SetTimer, MonitorActiveWindowChange

Gui, +AlwaysOnTop
Gui, Add, Edit, h100 w200 vactivewindow, % getTitleByHwnd(currActiveWindow)
Gui, Show, x0 y0,Active Window title
return

MonitorActiveWindowChange:
   currActiveWindow := WinExist("A")
   if currActiveWindow != lastActiveWindow
   {
        lastActiveWindow := currActiveWindow
        ; do some stuff - in this case, display the window title
        GuiControl, , activewindow, % getTitleByHwnd(currActiveWindow)   
   }
return

getTitleByHwnd(hwnd) {
    WinGetTitle, x, ahk_id %hwnd%
    return x
}

GuiClose:
Exitapp


Is there a better way than a timer like this to figure out when the active window has changed?

Also, the timer in this code runs 4 times a second - will this be a problem if the script is running all the time? I don't currently know enough about performance issues to know whether it will be significant or not.

Any thoughts/help would be greatly appreciated.
Back to top
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1271

PostPosted: Tue Oct 07, 2008 12:36 am    Post subject: Reply with quote

You could use ShellHook or WinEventHook to catch active window changes, but I don't really see the advantage over a 250ms timer in this instance unless you really need quicker detection.
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
pokercurious



Joined: 16 Dec 2007
Posts: 48

PostPosted: Tue Oct 07, 2008 12:59 am    Post subject: Reply with quote

Serenity wrote:
You could use ShellHook or WinEventHook to catch active window changes, but I don't really see the advantage over a 250ms timer in this instance unless you really need quicker detection.


No, I don't need quicker detection - 250ms is plenty quick. The main thing I'm curious about is whether or not running this script all the time in the background will have an impact on performance overall.

And I guess I could just finish the script and see, but there's a lot to do before it's done - I just thought I'd ask upfront if there was a better way.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group