Search for ClassNN with RegEx pattern

Get help with using AutoHotkey and its commands and hotkeys
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Search for ClassNN with RegEx pattern

01 Mar 2016, 15:31

I've hit a bit of a snag...

Often I use the ControlClick statement to click on specific parts of windows which are inaccessible via tab/alt (for some reason).

Code: Select all

ControlClick,SysHeader321,ahk_exe InnovyzeWC.exe,,Left
The problem is, often the SysHeader will not be SysHeader321. Sometimes it is SysHeader322 or SysHeader310 or SysHeader\d*.

Is there perhaps a way to search for a "SysHeader\d*" with regex and then click on the first one found?

Thanks in advance!
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: Search for ClassNN with RegEx pattern

01 Mar 2016, 17:11

-Untested-

Code: Select all

winget, controls, ControlList, ahk_exe InnovyzeWC.exe
Loop, Parse, controls, `n
	if(RegExMatch(A_LoopField, "SysHeader\d*")) {
		ControlClick, %A_LoopField%, ahk_exe InnovyzeWC.exe,, Left
		break
	}
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Re: Search for ClassNN with RegEx pattern

01 Mar 2016, 17:50

Thanks for the reply wizard. Ironically I was having similar thoughts when I was looking at WinGet earlier though I didn't quite know how to parse the string so you've helped me a bunch there! I will try it out tomorrow (the only computers i have at home are Macs...) but it looks like it'd work :)
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Search for ClassNN with RegEx pattern

01 Mar 2016, 17:57

AutoHotkey assigns the ClassNN based on the window class (SysHeader32) and NN/occurrence number (1, 2, 3, etc.) as AutoHotkey encounters windows of that class while enumerating the controls. There should never be a SysHeader322 without a SysHeader321. There is never a SysHeader320. So I would expect wizardzedd's code to always act on SysHeader321. In that case, you need some way of identifying which SysHeader32 control you want.
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Re: Search for ClassNN with RegEx pattern

02 Mar 2016, 14:44

Hmm well it seems to be working so far.... I guess I will need to test it in multiple different scenarios to be sure it's working fine...

I totally wish there was a better way to target this window than with ClassNN but sadly that's the only difference and I need to switch focus to that window somehow! :/...

I will definitely be doing further testing though :)
DRocks
Posts: 559
Joined: 08 May 2018, 10:20

Re: Search for ClassNN with RegEx pattern

08 May 2018, 10:31

Oh my God, Guys,
I've been searching for this for the last 3 weeks and nothing worked apart from this example code by wizardzedd.
Thank you so much for posting this.

I am using it to match a subpattern in changing ClassNN of specific buttons in my account software.

Code: Select all

		«::
			; Skip to TRANSPORT button
			winget, controls, ControlList, Achats|fournisseurs|Charges
			Loop, Parse, controls, `n
				if(RegExMatch(A_LoopField, "WindowsForms10.EDIT.app.0.(?:.*)_r38_ad114", Match))
				; (?:.*)This is the symbol that allows the changing subpattern to exist in the button ClassNN
				; My button is always ending with "_r38_ad114" but the subpattern is changing from file to file.
				; This is why I needed a RexExMatch to get the full button ClassNN with its unique subpattern into the "Match" variable
				; Having the Match variable with the new full ClassNN of the TRANSPORT Button, it can now be used as the Control's name and it works.
				{
					ControlClick, %Match%, Achats|fournisseurs|Charges,, Left
					break
				}
			;MsgBox %controls%
			;MsgBox %Match%
			return

Return to “Ask For Help”

Who is online

Users browsing this forum: jackn11, LeroyMcCheeks and 34 guests