 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Mayhem
Joined: 20 Aug 2004 Posts: 104
|
Posted: Wed Apr 20, 2005 6:14 pm Post subject: need some help making a autodetect script |
|
|
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  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Wed Apr 20, 2005 7:22 pm Post subject: |
|
|
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 |
|
 |
Mayhem
Joined: 20 Aug 2004 Posts: 104
|
Posted: Wed Apr 20, 2005 10:05 pm Post subject: |
|
|
oh wow! This works perfectly.
Thanks Chris! |
|
| Back to top |
|
 |
Mayhem
Joined: 20 Aug 2004 Posts: 104
|
Posted: Wed Apr 20, 2005 11:26 pm Post subject: |
|
|
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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10480
|
Posted: Thu Apr 21, 2005 1:51 am Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|