How to determine classsNN of a control by its color or by its location in autohotkey?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
manoj aggarwal

How to determine classsNN of a control by its color or by its location in autohotkey?

06 Nov 2015, 22:45

Friends I want to retrieve the text from a control using controlgettext command. I tried to use classNN of the specific control to retrieve its text but the classNN keeps changing so it caused problem. So I automated the mouse pointer to go to the specific control to retrieve its classNN. I also tried to use ahk_id of the specific control to retrieve its text but it has the same problem also i.e. it also keeps on changing. So I want a way to directly retrieve the classNN from the color of the specific control. My codes are these-

Code: Select all

PixelSearch, Px, Py, 131, 302, 214, 316, 0xCEFFCE, 3, Fast RGB  
;first it searches the color of the control in the given coordinates on the screen

sleep 100

mousemove %Px%, %Py%  ;then the mouse pointer moves to that control

sleep 100

MouseGetPos, X, Y, WIN, CONTROL ;then classNN is retrieved by Mousegetpos command

sleep 100

ControlGetText, OutputVar, %CONTROL%, Finacle - Microsoft Internet Explorer
;then text is retrieved from controlgettext command using classNN
sleep 100
msgbox the text of the control is %OutputVar%
So kindly tell me is there any way to retrieve classNN of the specific control by its color? I do not want to move the mouse pointer to the specific control first and then to retrieve its classNN. I want any direct way to retrieve classNN of the specific control by its color or by its location on the screen. Please help. Thanks a lot.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

06 Nov 2015, 23:49

I believe that Microsoft Internet Explorer will not respond to ControlGetText, OutputVar, %CONTROL%, Finacle - Microsoft Internet Explorer
This command will work with standard controls, it will not work for controls on webpages.

Check the content of the variable CONTROL, after MouseGetPos with an additional MsgBox

Maybe you can retrieve the text you want with UrlDownloadToFile
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

07 Nov 2015, 22:41

Dear @wolf_II the codes are working perfectly in IE window. I only want that if there is any control under specific coordinates then that control's ClassNN should be retrieved. As There are so many controls on the screen and their classNN keeps changing. Only two things do not change first is its location on screen and second is its color. so can't we retrieve the classNN of the control by its location or color? as

Code: Select all

PixelSearch, Px, Py, 131, 302, 214, 316, 0xCEFFCE, 3, Fast RGB
now if there is any control under the coordinates %Px% and %Py% , then its classNN should be retrieved (without moving the mouse pointer to these coordinates). Please help me. Thanks
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

08 Nov 2015, 02:42

You can try to call WindowFromPoint which might retrieve the ahk_id of the control with some luck.
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

08 Nov 2015, 04:51

dear @just me, kindly tell me what is WindowFromPoint? as far as i researched it is a utility of c++. So don't know whether it will work in autohotkey environment or not. if it works then how? Please help. Thanks.
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

08 Nov 2015, 07:19

Code: Select all

PixelSearch, Px, Py, 131, 302, 214, 316, 0xCEFFCE, 3, Fast RGB
If (ErrorLevel = 0) { ; found
   Point := (Px & 0xFFFFFFFF) | ((Py & 0xFFFFFFFF) << 32)
   hCtrl := DllCall("WindowFromPoint", "Int64", Point, "UPtr") ; retrieves the ahk_id of the control that contains the specified point
}
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

08 Nov 2015, 08:08

dear @just me kindly tell me how to retrieve ahk_id from these codes as after running these codes nothing is happening. when i added

Code: Select all

msgbox %hCtrl%
then it is showing a 6 digit value that is 460136. I think it is not ahk_id. As far as i know ahk_id is like this 0x3e0532. Kindly guide me. thanks..
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

08 Nov 2015, 08:16

AHK commands/functions retrieve the hexadecimal format, but you can safely pass a decimal integer value as an ahk_id.
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

09 Nov 2015, 00:50

Dear @just me, thanks for your great guidance. But sir the codes are still not working. I used the codes like this-

Code: Select all

f1::       
 PixelSearch, Px, Py, 131, 302, 214, 316, 0xCEFFCE, 3, Fast RGB
If (ErrorLevel = 0) { ; found
   Point := (Px & 0xFFFFFFFF) | ((Py & 0xFFFFFFFF) << 32)
   hCtrl := DllCall("WindowFromPoint", "Int64", Point, "UPtr") ; retrieves the ahk_id of the control that contains the specified point
}
ControlGetText, OutputVar,, ahk_id 0x%hCtrl%

Send %OutputVar%  
But it is sending nothing while it should send the text of the control. What is the problem in the codes. Please guide me. Thanks.
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

09 Nov 2015, 02:18

As I said, you can use the decimal number as an ahk_id. Remove the 0x.
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

09 Nov 2015, 02:33

Dear @just me First i tried %hCtrl% but i did not work, then i tried this 0x%hCtrl% but i also not worked. What should we do next. Please help. Thanks a lot.
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

09 Nov 2015, 05:26

Sorry, my bad. I don't use PixelSearch and did'nt notice that the returned coordinates are relative whereas WindowFromPoint needs screen coordinates. Try to add CoordMode, Pixel, Screen.
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

09 Nov 2015, 09:40

Dear @just me, i am grateful to you for your kind support. But sir the codes are still not working. i tried to use codes like this-

Code: Select all

f1:: 
CoordMode, Pixel, Screen.      
 PixelSearch, Px, Py, 131, 302, 214, 316, 0xCEFFCE, 3, Fast RGB
If (ErrorLevel = 0) { ; found
   Point := (Px & 0xFFFFFFFF) | ((Py & 0xFFFFFFFF) << 32)
   hCtrl := DllCall("WindowFromPoint", "Int64", Point, "UPtr") ; retrieves the ahk_id of the control that contains the specified point
}
ControlGetText, OutputVar,, ahk_id %hCtrl%
 Send %OutputVar% 
return
but still it is sending nothing. i do not know where we are making mistake. anyway if there is rectification that we can make in these codes then do share with me. moreover if there is any other way to do that then also provide me your kind guidance. i am damn sure you will certainly find out any way to do that. thanks a lot sir. hats off to you.
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

10 Nov 2015, 02:13

Dear @just me, as we used function windowfrompoint into our codes. But while reading about this function i come to know that WindowFromPoint function Retrieves a handle to the window that contains the specified point. As you can also read from here https://msdn.microsoft.com/en-us/librar ... s.85).aspx

So if it retrieves the window's handle then we are making mistake as we require specific control's handle. I may Be wrong. So your opinion and guidance is required. Thanks sir..
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

10 Nov 2015, 03:08

Dear manoj aggarwal, all controls are child windows so the function can be used for controls, too. But it might be my fault again. All coordinates of the PixelSearch command use the same coordinate mode. So if we change the coordinate mode the search rectangle would have to be adjusted, which might not be desirable in this case. So let's try another (last) attempt:

Code: Select all

#IfWinActive, Finacle - Microsoft Internet Explorer ; create a context-sensitive hotkey
f1::
PixelSearch, Px, Py, 131, 302, 214, 316, 0xCEFFCE, 3, Fast RGB
If (ErrorLevel = 0) { ; found
   WinGetPos, Wx, Wy ; #IfWinActive has set the Last Found WIndow
   Px += Wx ; change to screen coordinates
   Py += Wy ; change to screen coordinates
   Point := (Px & 0xFFFFFFFF) | ((Py & 0xFFFFFFFF) << 32)
   hCtrl := DllCall("WindowFromPoint", "Int64", Point, "UPtr") ; retrieves the ahk_id of the control that contains the specified point
   ControlGetText, OutputVar,, ahk_id %hCtrl%
   Send %OutputVar%}
}
return
#IfWinActive
*untested*
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

10 Nov 2015, 09:43

Dear @just me, first of all i appreciate your great support and afforts for others. you are really a gem of autohotkey and genius. But sir the codes are still not working. But i am not sad as i have learnt a lot under your guidance. I hope you will keep helping the apprentices like me. further i urge if you get the solution of this problem by any other way, then not forget to share it with me. thanks a lot sir. again you are master of autohotkey. keep it up sir... :salute: :salute:
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

10 Nov 2015, 10:57

Hi, just as a last test. When your window is active, move the mouse on the control and press F1. What does the MessageBox show?

Code: Select all

F1::
   MouseGetPos, Px, Py, , ClassNN
   MouseGetPos, , , , hMCtrl, 2
   hMCtrl += 0
   WinGetPos, Wx, Wy, , , A
   X := Px + Wx ; change to screen coordinates
   Y := Py + Wy ; change to screen coordinates
   Point := (X & 0xFFFFFFFF) | ((Y & 0xFFFFFFFF) << 32)
   hCtrl := DllCall("WindowFromPoint", "Int64", Point, "UPtr") ; retrieves the ahk_id of the control that contains the specified point
   WinGetClass, ClassName, ahk_id %hCtrl%
   ControlGetText, OutputVar,, ahk_id %hCtrl%
   MsgBox, %hCtrl% - %hMCtrl%`n`n%ClassName% - %ClassNN%`n`n%Px% - %Wx% - %Py% - %Wy%`n`n%OutputVar%
Return
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

10 Nov 2015, 11:14

Manually get the ClassNN and save it to the var in the below code and run it:

Code: Select all

var=<< classNN here >>
WinGet, cList, ControlList, Finacle - Microsoft Internet Explorer
if	!InStr(cList,var)
{
	MsgBox, The control does not exist in the window.
	return
}
Loop, parse, cList, `n, `r
	i :=	A_Index
Until	(A_LoopField=var)
MsgBox, The control is number %i% in the window.
return
Make note of that number. Run the code a few times when you know that the ClassNN has changed and see if it is always in the same position in the order of controls in the window. If it is, then you can work around it by pulling the control list and using the control at that position in the order:

Code: Select all

i=<< put the control position (as number) here >>
WinGet, cList, ControlList, Finacle - Microsoft Internet Explorer
Loop, parse, cList, `n, `r
	ctrl :=	A_LoopField
Until	(A_LoopField=i)
ControlGetText, OutputVar, %ctrl%, Finacle - Microsoft Internet Explorer
manoj aggarwal

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

12 Nov 2015, 00:09

Dear @just me, first sorry I could not reply earlier as festival season is going on here in india. Second I show my gratitude towards you for your great zeal to help me. Dear just me I run the codes suggested by you after putting mouse pointer over the control and it showed me a massage box whose snapshot I am putting here-
http://i.imgur.com/dX5X6XZ.png

As the red box is that control whose classNN or ahk_id I require. But both of them keep changing.
just me
Posts: 9575
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to determine classsNN of a control by its color or by its location in autohotkey?

12 Nov 2015, 01:19

Hello manoj,

obviously WindowFromPoint gets the wrong control. I'll have to think about another method. I'm pretty sure it can be solved.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Mateusz53, mikeyww, MrHue and 325 guests