Have been having a number of scripts stop working for some updated applications, and it appears that ControlGetText is not getting info from the control name anymore. Not sure if it's also an issue with the latest version of AutoHotkey. I would do a simple test script using ControlGetText and Msgbox, to see what's happening. Getting back blank in the Msgbox.
It's odd, as in WindowSpy.ahk can see the text on the control, but not test scripts that I make. As a workaround, I'm using WinGetText. That command will often find the text I'm looking for, and then IfInString or InStr can be used.
1) Has anybody else been having issues lately with ContolGetText?
2) What are reasons why AutoHotkey may not be able to get text from a control?
3) Can anyone suggest some other methods that can be tried to get text from a control?
ControlGetText Issues
Re: ControlGetText Issues
double check the control names they do change sometimes, some programs button1 can turn into button2SOTE wrote:Have been having a number of scripts stop working for some updated applications, and it appears that ControlGetText is not getting info from the control name anymore. Not sure if it's also an issue with the latest version of AutoHotkey. I would do a simple test script using ControlGetText and Msgbox, to see what's happening. Getting back blank in the Msgbox.
It's odd, as in WindowSpy.ahk can see the text on the control, but not test scripts that I make. As a workaround, I'm using WinGetText. That command will often find the text I'm looking for, and then IfInString or InStr can be used.
1) Has anybody else been having issues lately with ContolGetText?
2) What are reasons why AutoHotkey may not be able to get text from a control?
3) Can anyone suggest some other methods that can be tried to get text from a control?
Re: ControlGetText Issues
True, when some programs are updated, they do change the button numbers. Thus ControlSend or Postmessage can help with that.Haxt0r Baxtor wrote: double check the control names they do change sometimes, some programs button1 can turn into button2
However, I checked for this. When I do the test script, I put the button name as reported by WindowSpy.ahk or other scripts that are similar.
Example-
Code: Select all
ControlGetText, ShowTheText, BUTTON2, Title Of Windows Program
Re: ControlGetText Issues
try running your script as admin and also remember that programs can block you from pulling textSOTE wrote:True, when some programs are updated, they do change the button numbers. Thus ControlSend or Postmessage can help with that.Haxt0r Baxtor wrote: double check the control names they do change sometimes, some programs button1 can turn into button2
However, I checked for this. When I do the test script, I put the button name as reported by WindowSpy.ahk or other scripts that are similar.
Example-The test script can't pull the text from the control, in various programs.Code: Select all
ControlGetText, ShowTheText, BUTTON2, Title Of Windows Program
Re: ControlGetText Issues
Yes, I did run the program as administrator. Possibly might be problems with the version of AutoHotkey used. There seems to be a difference in behavior.Haxt0r Baxtor wrote:try running your script as admin and also remember that programs can block you from pulling textSOTE wrote:True, when some programs are updated, they do change the button numbers. Thus ControlSend or Postmessage can help with that.Haxt0r Baxtor wrote: double check the control names they do change sometimes, some programs button1 can turn into button2
However, I checked for this. When I do the test script, I put the button name as reported by WindowSpy.ahk or other scripts that are similar.
Example-The test script can't pull the text from the control, in various programs.Code: Select all
ControlGetText, ShowTheText, BUTTON2, Title Of Windows Program
-
- Posts: 860
- Joined: 21 Dec 2015, 02:34
Re: ControlGetText Issues
does this make any difference?
Code: Select all
ControlGetText, ShowTheText, Static1, Title Of Windows Program ;change Static1 to whichever the button is such as Static2, or Static3, etc
Re: ControlGetText Issues
I'm having a similar problem: Works on some controls but not on others. Would seem odd that the program is intentionally blocking the text (UltraSearch, ClassNN = "TButtonedEdit1"; works fine on the other controls in that window). Any thoughts on how to diagnose/workaround? Could it be the difference between a Standard windows control vs. a custom control and if so, how can one tell the type of control used? Style of "TButtonedEdit1": 0x000000C0, WS_CHILD, WS_CLIPSIBLINGS, WS_TABSTOP, WS_VISIBLEHaxt0r Baxtor wrote: ↑07 Jan 2018, 02:30... programs can block you from pulling text
WindowSpy.ahk doesn't retrieve the text either, but AutoIt Control Viewer does. Wonder how their tool is doing it??
Re: ControlGetText Issues
Try ControlClickByControlText(), If the button has exposed text, it'll find it, else it's probably either a custom control(subcontrol),...
@SAbboushi
Most likely that uses Acc or something like that to get the control text....
@SAbboushi
Most likely that uses Acc or something like that to get the control text....
live ? long & prosper : regards
Re: ControlGetText Issues
Thanks CyLON. I tried your script but didn't get a result (including for controls that ControlGetText() work on. Maybe I'm doing something wrong (I didn't know what to use for searchStr):
I tried sending a message hoping that would work, but no joy (I thought sending a message is supposed to work for custom controls?). result = "" and ErrorLevel = 1. Works fine for other controls:
WinGetText( AppWinTitle ) shows the text.
Code: Select all
ControlClickByControlText(searchStr, controlName:="TButtonedEdit1", winTitle:="UltraSearch",passes:=1)
Code: Select all
buffer_size := 20
; ensure AHk properly updates variable by initializing with non-zero value
VarSetCapacity( buffer, buffer_size, 1 )
/*
WM_GETTEXT wParam = (WPARAM) cchTextMax;
lParam = (LPARAM) lpszText;
Parameters:
cchTextMax
Specifies the maximum number of characters to be copied, including the terminating null character.
lpszText
Long pointer to the buffer that is to receive the text.
Return Values
The return value is the number of characters copied.
*/
result:=SendMessage( 0xD, buffer_size, &buffer, "TButtonedEdit1", AppWinTitle ) ; 0xD = WM_GETTEXT
What's Acc?
Re: ControlGetText Issues
SAbboushi wrote: ↑07 Dec 2018, 00:45Thanks CyLON. I tried your script but didn't get a result (including for controls that ControlGetText() work on. Maybe I'm doing something wrong (I didn't know what to use for searchStr):I tried sending a message hoping that would work, but no joy (I thought sending a message is supposed to work for custom controls?). result = "" and ErrorLevel = 1. Works fine for other controls:Code: Select all
ControlClickByControlText(searchStr, controlName:="TButtonedEdit1", winTitle:="UltraSearch",passes:=1)
WinGetText( AppWinTitle ) shows the text.Code: Select all
buffer_size := 20 ; ensure AHk properly updates variable by initializing with non-zero value VarSetCapacity( buffer, buffer_size, 1 ) /* WM_GETTEXT wParam = (WPARAM) cchTextMax; lParam = (LPARAM) lpszText; Parameters: cchTextMax Specifies the maximum number of characters to be copied, including the terminating null character. lpszText Long pointer to the buffer that is to receive the text. Return Values The return value is the number of characters copied. */ result:=SendMessage( 0xD, buffer_size, &buffer, "TButtonedEdit1", AppWinTitle ) ; 0xD = WM_GETTEXT
What's Acc?
ACC:
https://autohotkey.com/boards/viewtopic.php?t=26201
Search String is the control the text(button text for example(ok,cancel,...)) on the control,It's what the function searches for.
I Suggested my function as a solution so that @SOTE can test if the control does have an active text,that is somehow hidden underneath another control.... If the control doesn't respond to an attempt by the function,then the control text is most likely inside a custom control.....
live ? long & prosper : regards
Re: ControlGetText Issues
Run this code (fill in the window title as indicated) and tell me if the text of the control that you're looking for shows up in the list:
Code: Select all
WinGet, cList, ControlList, << your window title here >>
Loop, Parse, cList, `n, `r
{
ControlGetText, t, %A_LoopField%, << your window title here >>
out .= A_LoopField ":`t`t" t
}
MsgBox % t
return
Re: ControlGetText Issues
Thanks sinkfaze: the control is listed, but no text. Just to clarify, this control is / appears to be an edit box. The only unusual (visible) aspect is that when I type text into the box, a warning icon overlaps the right edge of the box (to warn that searching for text is a slow process). Note that the icon (size/position) does not overlap the text:
(Edit: don't know why this image isn't displaying... try https://1drv.ms/u/s!AoxenOc43-zegZNFoNwRO2e_OSAnLw)
For anyone else that wants to use sinkfaze's script, modify a couple lines:
1) if one control is above another, then a spy utility might not be able to retrieve e.g. text from a control that is overlapped by another?
2) if I'm using ControlGetText() and specifying the control's ClassNN or HWND, then I suspect it wouldn't matter whether the control is overlapped or not?
(Edit: don't know why this image isn't displaying... try https://1drv.ms/u/s!AoxenOc43-zegZNFoNwRO2e_OSAnLw)
For anyone else that wants to use sinkfaze's script, modify a couple lines:
Code: Select all
out .= A_LoopField ":`t`t" t "`n"
}
MsgBox % out
So since this control is an edit box, I should set Search String to be the text that I've typed into the edit box?
Just to make sure I understand:
1) if one control is above another, then a spy utility might not be able to retrieve e.g. text from a control that is overlapped by another?
2) if I'm using ControlGetText() and specifying the control's ClassNN or HWND, then I suspect it wouldn't matter whether the control is overlapped or not?
3) So the link I posted above seems to be incorrect:
Last edited by SAbboushi on 07 Dec 2018, 12:34, edited 1 time in total.
Re: ControlGetText Issues
CyLON: I entered "asdf" into the edit box and tried:
Your script didn't respond with anything...
Code: Select all
ControlClickByControlText(searchStr:="asdf", controlName:="TButtonedEdit1", winTitle:="UltraSearch",passes:=1)
Re: ControlGetText Issues
I'm thinking this control is not a standard Windows Control and might be this: TButtonedEdit_(Delphi)
Can anyone make sense of this and suggest whether or not I can get/set the text in this control from within AHK?
Can anyone make sense of this and suggest whether or not I can get/set the text in this control from within AHK?