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 

Monitor a Window, on Title change set a new title?

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



Joined: 21 May 2008
Posts: 6
Location: Michigan, US

PostPosted: Wed May 21, 2008 6:29 pm    Post subject: Monitor a Window, on Title change set a new title? Reply with quote

Here is my current script which works great for what I am doing, only problem is now at intermittent times the window title will change (reloads the window essentially). It changes it back to "EVE"

Code:

#Persistent

Ico :="c:\downloads\AM-117-g12.ico"
Menu,Tray,Icon,%Ico%

WinActivate, ahk_class triuiScreen
WinSetTitle, EVE,, Network Monitor
hIcon := DllCall( "LoadImage", UInt,0, Str,Ico, UInt,1, UInt,0, UInt,0, UInt,0x10 )
SendMessage, 0x80, 0, hIcon ,, ahk_class triuiScreen  ; Small Icon
SendMessage, 0x80, 1, hIcon ,, ahk_class triuiScreen  ; Big Icon

#IfWinActive ahk_class triuiScreen
+Capslock::Capslock
Capslock::WinMinimize
return
#IfWinActive
return


How I can have it monitor the window and when it changes, change the window title back to "Network Monitor" without activating the window?
Back to top
View user's profile Send private message
Extreminador



Joined: 05 May 2008
Posts: 22

PostPosted: Wed May 21, 2008 7:21 pm    Post subject: Reply with quote

You don´t need to activate the window, you can use the class or the id ot whatever to set the title with out activated.

Code:

WinSetTitle, ahk_class triuiScreen, , NetWork Monitor
Back to top
View user's profile Send private message
panterafreak



Joined: 21 May 2008
Posts: 6
Location: Michigan, US

PostPosted: Wed May 21, 2008 7:34 pm    Post subject: Reply with quote

That solves the activation thing, thanks, i figured there was a way to do that easily, now how can I monitor that window so when it changes back to "EVE" that it will set it back to "Network Monitor" or is always going to do that since the script will sit in my tray?
Back to top
View user's profile Send private message
Extreminador



Joined: 05 May 2008
Posts: 22

PostPosted: Wed May 21, 2008 7:58 pm    Post subject: Reply with quote

WinGetTitle
Back to top
View user's profile Send private message
panterafreak



Joined: 21 May 2008
Posts: 6
Location: Michigan, US

PostPosted: Wed May 21, 2008 8:55 pm    Post subject: Reply with quote

I've modified my script as below, however I must be missing something with the loop because it isn't constantly changing the window title (messed around in the window to modify it's title by clicking around).

Code:
#Persistent

Ico :="c:\downloads\AM-117-g12.ico"
Menu,Tray,Icon,%Ico%

Loop
{
WinGetTitle, Title, ahk_class triuiScreen
if Title = EVE
{
   WinSetTitle, ahk_class triuiScreen, , Network Monitor
   hIcon := DllCall( "LoadImage", UInt,0, Str,Ico, UInt,1, UInt,0, UInt,0, UInt,0x10 )
   SendMessage, 0x80, 0, hIcon ,, ahk_class triuiScreen  ; Small Icon
   SendMessage, 0x80, 1, hIcon ,, ahk_class triuiScreen  ; Big Icon
}
else if Title = Network Monitor
   Return
}

#IfWinActive ahk_class triuiScreen
+Capslock::Capslock
Capslock::WinMinimize
return
#IfWinActive
return


This will change the title if I reload the script so the if/then logic seems to be working properly.
Back to top
View user's profile Send private message
panterafreak



Joined: 21 May 2008
Posts: 6
Location: Michigan, US

PostPosted: Thu May 22, 2008 12:54 pm    Post subject: Reply with quote

I got the loop to work (used Continue in place of Return on the else if part of the loop). However now autohotkey takes like 24% cpu constantly while the script is active (probably because its constantly looping to check). If this is the correct behavior i guess I don't want a continuous loop, a timer for every x number would reduce the cpu usage?
Back to top
View user's profile Send private message
CannedCheese



Joined: 21 May 2008
Posts: 85

PostPosted: Thu May 22, 2008 3:41 pm    Post subject: Reply with quote

try setbatchlines
Back to top
View user's profile Send private message
panterafreak



Joined: 21 May 2008
Posts: 6
Location: Michigan, US

PostPosted: Thu May 22, 2008 5:16 pm    Post subject: Reply with quote

I tried setbatchlines to 1 second and 10 second, I assume at the top of the script (right after the #persistant) however that brought usage up to 40-50%. I tried putting a "sleep, 1000" in the loop but that seems to break the loop after it changes the title the first time.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Thu May 22, 2008 10:37 pm    Post subject: Reply with quote

try setbatchlines -1
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
panterafreak



Joined: 21 May 2008
Posts: 6
Location: Michigan, US

PostPosted: Fri May 23, 2008 12:16 pm    Post subject: Reply with quote

Looks like I at some point messing around with the script put the Return back into the loop which seemed to break it and create that additional cpu load. I set "setbatchlines 1" and replaced the Return with Continue (again) and it seems to be working with low to no cpu load while changing the window. Thanks for all the help guys!
Back to top
View user's profile Send private message
BoBo²
Guest





PostPosted: Fri May 23, 2008 1:02 pm    Post subject: Reply with quote

Ceck out SetTimer to replace the resource consuming Loop.
Back to top
Display posts from previous:   
Post new topic   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