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 

need some help making a autodetect script

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



Joined: 20 Aug 2004
Posts: 104

PostPosted: Wed Apr 20, 2005 6:14 pm    Post subject: need some help making a autodetect script Reply with quote

I'm trying to make a script that will autodetect a certain control name (I forget the exact name, so lets call it "GameX") that belongs to a unknown window title.

GameX has serveral entries in the control list. (GameX1, GameX2, and so on)

I'm looking for GameX? that has the Width = 200 and Height = 450.

If that criteria matches, get the control name (GameX3 for example) and save it as a variable and retrieve the window unique ID # that the control we just found belongs to.

Child window support would be nice as well. (being able to autodetect if the control name if it's not in a parent window)

any takers on this challenge? i have paypal and i know how to use it Very Happy
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Wed Apr 20, 2005 7:22 pm    Post subject: Reply with quote

If you know the class name(s) of the parent window(s) that always own this control, you could do something like the following. If you don't know the class names, you could omit the last parameter of the first WinGet line so that it searches through all windows of the entire system:
Code:
#space::
FoundWindow =
FoundControl =
WinGet, ID, List, ahk_class MyClassName
Loop %id%  ; For each window, check its controls for a match.
{
   FoundWindow := ID%A_Index%
   WinGet, ControlList, ControlList, ahk_id %FoundWindow%
   Loop, Parse, ControlList, `n
   {
      ControlGetPos, Cx, Cy, Cw, Ch, %A_LoopField%, ahk_id %FoundWindow%
      if (Cw = 200 and Ch = 450)
      {
         FoundControl := A_LoopField
         break
      }
   }
   if FoundControl       ; **** Added.
      break
}

if FoundControl
   MsgBox Win: %FoundWindow%`nControl: %FoundControl%
return

Edit: Fixed outer loop to break when a match was found by the inner.


Last edited by Chris on Thu Apr 21, 2005 1:48 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Mayhem



Joined: 20 Aug 2004
Posts: 104

PostPosted: Wed Apr 20, 2005 10:05 pm    Post subject: Reply with quote

oh wow! This works perfectly.

Thanks Chris!
Back to top
View user's profile Send private message
Mayhem



Joined: 20 Aug 2004
Posts: 104

PostPosted: Wed Apr 20, 2005 11:26 pm    Post subject: Reply with quote

I tried to take this one step further ... wanted to look for 2 different control names (same width / height specs)

In the control list, there is GameX1, GameX2, GameX3, etc. All match the Width and Height specs. When i use Window Spy, it shows :

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: GameX5

You script stops at the first match (GameX1). Please have a look at my addition (at the bottom) and let me know if this can be done differently / more efficently. I've also noticed that i get a completely different unique window ID # when doing the MouseGetPos than what your script says.

Code:

FoundWindow =
FoundControl =
WinGet, ID, List
Loop %id%  ; For each window, check its controls for a match.
{
   FoundWindow := ID%A_Index%
   WinGet, ControlList, ControlList, ahk_id %FoundWindow%
   Loop, Parse, ControlList, `n
   {
      ControlGetPos, Cx, Cy, Cw, Ch, %A_LoopField%, ahk_id %FoundWindow%
      if (Cw = 200 and Ch = 450)
      {
         If A_LoopField contains GameX,GameY
         {
                    FoundControl := A_LoopField
                   break
                }
                }
   }
}
ControlGetPos, X, Y, W, H, %FoundControl%, ahk_id %FoundWindow%
EnvAdd, X, 50
EnvAdd, Y, 50
MouseGetPos, xpos, ypos
MouseMove, %X%, %Y%
MouseGetPos, , , Window, Control, 1 ; now it reads GameX5 as the control
MouseMove, %xpos%, %ypos%
MsgBox, window = %Window%`ncontrol = %Control%
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Thu Apr 21, 2005 1:51 am    Post subject: Reply with quote

Mayhem wrote:
Please have a look at my addition (at the bottom) and let me know if this can be done differently / more efficently.
That approach seems okay if you don't mind moving the mouse. Alternatively, you could have the loops find two controls instead of one by having variables for two controls: FoundControl1 and 2.

Quote:
I've also noticed that i get a completely different unique window ID # when doing the MouseGetPos than what your script says.
My script above had a bug that I've fixed by adding the following two lines at the bottom of the outer loop:
if FoundControl
break
Back to top
View user's profile Send private message Send e-mail
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