controlgetting text using coordinates Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

controlgetting text using coordinates

11 Oct 2018, 07:07

Hello.

A known classNN of an application, say targetClassNN, has a bunch of cells populated with text data, meaning that each of the data cells do not have unique ClassNNs.
The problem is that I can not use controlgettextto get text from a certain cell, say at x100 y200, because it does not support coordinates.

So how do I get text at x100 y200 using control functions, given a targetClassNN?
Any ideas are welcome.

Code: Select all

^+!F12::
{
    controlclick,%targetClassNN%,,,,,Pos x100 y200
    controlgettext,myText,%targetClassNN%
    msgbox %myText%
    return
}
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: controlgetting text using coordinates  Topic is solved

11 Oct 2018, 22:39

Given this is a hotkey would it be so awkward if the cursor moved the cursor to target coord for an instant,besides this way you don't have to click on the control to activate it,so long as it's on screen...

Code: Select all

^+!F12::
MsgBox % ControlGetTextPos(140,158)
return

ControlGetTextPos(xCtrl,yCtrl){		;get text at a specific screen coordinate
	CoordMode, Mouse, Screen
	MouseGetPos, xx, yy	;current pos
	MouseMove, xCtrl, yCtrl, 0
	MouseGetPos, x, y, mID, mCtrl
	MouseMove, xx, yy	;back to original pos
	ControlGetText, outStr, %mCtrl%, ahk_id %mID%
	Return outStr
}
live ? long & prosper : regards
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

Re: controlgetting text using coordinates

12 Oct 2018, 10:47

paik1002 wrote: A known classNN of an application, say targetClassNN, has a bunch of cells populated with text data, meaning that each of the data cells do not have unique ClassNNs.
If "CyL0N" answer doesn't works, you could use brute force to get all text of the window:
https://autohotkey.com/docs/commands/WinGetText.htm

Code: Select all

DetectHiddenText, On
WinGetText, OutputVar, %ProgramTitle%	;; If the text is visible, this should show it.
DetectHiddenText, Off
Msgbox %OutputVar%
Once you have the whole text, use some string function to get exactly what you want (for example RegEx).

Cheers,
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: controlgetting text using coordinates

12 Oct 2018, 11:07

you have a different problem. but first:
paik1002 wrote: So how do I get text at x100 y200 using control functions, given a targetClassNN?
if you're satisfied moving the mouse, then CyLON's way is probably best

alternatively you could loop through all controls with WinGet,,ControlList and then ControlGetPos,x,y,w,h and check if the coordinate falls within the control's rect. but i THINK this has the problem if multiple controls are stacked on top of each other. consider a Tab control, with a text box inside a tab. the coordinate of the textbox would technically also fall inside the tab control also.

you could also try handle:= DllCall("WindowFromPoint", Int,x, Int,y) and then ControlGetText with the ahk_id %handle%

but now...

paik1002 wrote: A known classNN of an application, say targetClassNN, has a bunch of cells populated with text data, meaning that each of the data cells do not have unique ClassNNs.
ControlGetText is usually going to be used on a Static text control, or an Edit textbox control, or something like that. if you have ONE control that contains MULTIPLE textbox cells, then its probably some type of custom built control, and not a standard windows control. in which case, even if ControlGetText DID support coordinates, its unlikely it retrieve the data you'd want. because, the coordinate would just specify the single control, in which case i'd think ControlGetText would simply return ALL of the text, for all boxes. its kinda like a spreadsheet. if the actual spreadsheet grid is one big single control with one classNN, then when you ask to get the "text" of that big control, what are you really asking? to get the text of everything in that control.

so really, you want to get the text of one sub-textbox of a control. its weird because most controls aren't really built like that. normally each box has its own individual classNN. since this is a weird custom situation, the only solution i could think of is the most hackish way possible: click on box, send ^a, send ^c, move mouse back. i have to do this for my app because some games don't expose individual control classNN's for their textboxes and such. the entire game window is just one single control. it sucks

:(

paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: controlgetting text using coordinates

14 Oct 2018, 20:10

eqv wrote:
12 Oct 2018, 10:47
paik1002 wrote: A known classNN of an application, say targetClassNN, has a bunch of cells populated with text data, meaning that each of the data cells do not have unique ClassNNs.
If "CyL0N" answer doesn't works, you could use brute force to get all text of the window:
https://autohotkey.com/docs/commands/WinGetText.htm

Code: Select all

DetectHiddenText, On
WinGetText, OutputVar, %ProgramTitle%	;; If the text is visible, this should show it.
DetectHiddenText, Off
Msgbox %OutputVar%
Once you have the whole text, use some string function to get exactly what you want (for example RegEx).

Cheers,
Thanks. Your brute force method should've worked, but for some strange reason, AHK does not picked up the text at the specified location. Only part of data from the bunch of cells are extracted.
paik1002
Posts: 355
Joined: 28 Nov 2015, 02:45

Re: controlgetting text using coordinates

14 Oct 2018, 20:28

guest3456 wrote:
12 Oct 2018, 11:07
you have a different problem. but first:
paik1002 wrote: So how do I get text at x100 y200 using control functions, given a targetClassNN?
if you're satisfied moving the mouse, then CyLON's way is probably best

alternatively you could loop through all controls with WinGet,,ControlList and then ControlGetPos,x,y,w,h and check if the coordinate falls within the control's rect. but i THINK this has the problem if multiple controls are stacked on top of each other. consider a Tab control, with a text box inside a tab. the coordinate of the textbox would technically also fall inside the tab control also.

you could also try handle:= DllCall("WindowFromPoint", Int,x, Int,y) and then ControlGetText with the ahk_id %handle%

but now...

paik1002 wrote: A known classNN of an application, say targetClassNN, has a bunch of cells populated with text data, meaning that each of the data cells do not have unique ClassNNs.
ControlGetText is usually going to be used on a Static text control, or an Edit textbox control, or something like that. if you have ONE control that contains MULTIPLE textbox cells, then its probably some type of custom built control, and not a standard windows control. in which case, even if ControlGetText DID support coordinates, its unlikely it retrieve the data you'd want. because, the coordinate would just specify the single control, in which case i'd think ControlGetText would simply return ALL of the text, for all boxes. its kinda like a spreadsheet. if the actual spreadsheet grid is one big single control with one classNN, then when you ask to get the "text" of that big control, what are you really asking? to get the text of everything in that control.

so really, you want to get the text of one sub-textbox of a control. its weird because most controls aren't really built like that. normally each box has its own individual classNN. since this is a weird custom situation, the only solution i could think of is the most hackish way possible: click on box, send ^a, send ^c, move mouse back. i have to do this for my app because some games don't expose individual control classNN's for their textboxes and such. the entire game window is just one single control. it sucks

:(

Thank your for the input. I am trying to use control functions such that the mouse pointer is not moved in the first place. But as you have mentioned above, it seems this would not be possible for my application.

Also, I found that CyLON's way would work if the box at the location x100 y200 is clicked first. Maybe I am not looking at it correctly, since there seems to be be something strange going on with my application, as you have pointed out.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 215 guests