How to get a Control's ClassNN by coordinates ?http://www.autohotkey.com/forum/viewtop ... 4327#94327Case: I want to programatically click 1 four times in the windows Calculator and the ClassNN for 1 was changing every time it was run.
I run the Calculator and check the ClassNN for that particular button with Spy utility to find it as Button7.
Let us try to ascertian the exact coordinates of Button7
Code:
AppWinTitle := "Calculator" ; Make sure Calculator is running & not minimised
ID := WinExist(AppWinTitle)
WinGet, ClassNNList, ControlList, ahk_id %ID%
Loop, PARSE, ClassNNList, `n
{
ControlGetPos, X, Y, Width, Height, %A_LoopField%, ahk_id %ID%
NewList .= A_LoopField . " = " . X . "," . Y . "`n"
}
StringTrimRight, NewList, NewList, 1
MsgBox, 0, Control List: %AppWinTitle%, %NewList%
Ah yes! Button7 is located @ 57,179
Now, lets see on how to programatically retrieve the ClassNN of a control that is located @ 57,179 and click it four times.
Code:
AppWinTitle := "Calculator" ; Make sure the file is open
ID := WinExist(AppWinTitle)
WinGet, ClassNNList, ControlList, ahk_id %ID%
Loop, PARSE, ClassNNList, `n
{
ControlGetPos, X, Y, Width, Height, %A_LoopField%, ahk_id %ID%
If ( X=57 AND Y=179 ) {
ClassNN := A_LoopField
Break
}
}
MsgBox, % ClassNN ; Got the Control's ClassNN
Loop 4 ; Key in the amount = 1111
ControlClick , %ClassNN%, ahk_id %ID%
That is it ....
However, I noticed that:
Control positions are slightly different when Calculator is minimised.
ControlGetPos does not work when Calculator is minimised.
Calculator's control never change its ClassNN ..
( I used Calculator as an example )
Thanks to those who read this patiently.
Regards, 