 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
pokercurious
Joined: 16 Dec 2007 Posts: 48
|
Posted: Tue Oct 07, 2008 12:24 am Post subject: Monitoring active window changes & settimer questions |
|
|
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 |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Tue Oct 07, 2008 12:36 am Post subject: |
|
|
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 |
|
 |
pokercurious
Joined: 16 Dec 2007 Posts: 48
|
Posted: Tue Oct 07, 2008 12:59 am Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|