how to get correct controls if Text not detected in WinSpy?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

how to get correct controls if Text not detected in WinSpy?

Post by newcod3r » 15 May 2022, 17:45

Some window properties will show the "Shortcut" tab but not ALL of them. As such, the button number can be different too. The button text can't be displayed by WinSpy, so is there a better workaround that can confirm I am on the right tab?

Separately, what will be the best way to break a loop in such an instance? will errorlevel be the correct one?
image.png
image.png (29.69 KiB) Viewed 341 times

Code: Select all

Loop
{
	ControlGetText, Text, %SysTabControl321%, A ; ClassNN here
	If (Text = Shortcut)
	MsgBox ClassNN: %SysTabControl321%
}
return

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: how to get correct controls if Text not detected in WinSpy?

Post by mikeyww » 15 May 2022, 18:36

The ClassNN is not typically quoted. Example

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: how to get correct controls if Text not detected in WinSpy?

Post by boiler » 16 May 2022, 06:11

All three of these lines are wrong:

Code: Select all

	ControlGetText, Text, %SysTabControl321%, A ; ClassNN here
	If (Text = Shortcut)
	MsgBox ClassNN: %SysTabControl321%

Should be:

Code: Select all

	ControlGetText, Text, SysTabControl321, A ; ClassNN here
	If (Text = "Shortcut")
	MsgBox The selected tab for ClassNN:SysTabControl321 is 'Shortcut' ; this is what it seems you are trying to report

SysTabControl321 is not a variable, so you wouldn’t put % symbols around it. It is a literal string, so in legacy syntax, you put nothing around it. This is true for both the first and third line,

In the second line, it is an expression, so you need to put quotation marks around the literal string Shortcut.

There is never a case where you put % symbols around literal strings in either legacy syntax or expressions.

What you are telling the ControlGetText command is that you want to get the text from the control named SysTabControl321. You are not getting the name of the control and putting it in a variable named SysTabControl321. SysTabControl321 is the name of the control.

You wouldn’t break the loop based on the value of ErrorLevel. That doesn’t make sense here. You are checking the condition you want, so you would break based on the result of that if statement. Just replace the MsgBox line with the break command.

By the way, I have done no testing to see if ControlGetText returns the name of the selected tab (and only the name of the selected tab) for this control as your code is expecting.

Post Reply

Return to “Ask for Help (v1)”