SetTitleMatchMode RegEx does not work properly with ahk_exe

Report problems with documented functionality
Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 10:53

Hey,

I posted this before in the help section of this forum but nobody replied and after some more testing I recognized that SetTitleMatchMode RegEx does not work as expected with ahk_exe. It does its job well when it comes to standard title (what the window is called) and ahk_class, but not ahk_exe.

Code: Select all

; this works as expected
WinGet, window1_ID, ID, ahk_class i)^SomeClass$
 
; this does not work at all, no match
WinGet, window1_ID, ID, ahk_exe i)^SomeProg.exe$

; this, however, works
WinGet, window1_ID, ID, ahk_exe i)SomeProg.exe$
So the problem seems to be the circumflex.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 14:28

Leli196 wrote:I posted this before in the help section of this forum but nobody replied...
Please make sure that you have verified this problem with another user before posting in Bug Reports. Feel free to bump your post in Ask for Help if you have not received a reply within a few hours, but don't just assume that you have found a bug.

Code: Select all

; this works as expected
WinGet, window1_ID, ID, ahk_class i)^SomeClass$
There is no reason that that should work, and for me it doesn't. The problem isn't the circumflex or the options, the problem is how (or, more concisely, where) you're using it. Everything in the WinTitle field is the string upon which regex acts; not this SomeClass, but this ahk_class SomeClass. So this:

Code: Select all

i)^ahk_exe SomeProg.exe$
Is the correct way to use it, and I can successfully retrieve information from a window using ahk_exe in that manner.
Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 14:56

Well, for me your method does not work.
Regarding case the only way to ignore it is this:
(Let us assume the program has the following values: ahk_exe SomeProg.exe, ahk_class SomeClass)

Code: Select all

ahk_exe i)someprog.exe$
Neither this works:

Code: Select all

i)ahk_exe someprog.exe$
nor does this:

Code: Select all

i)^ahk_exe someprog.exe$
and this also fails:

Code: Select all

ahk_exe i)^someprog.exe$
Regarding your statement that ahk_exe is part of the string and therefore has to be included: I don't think so. This would require the command to not get a match with this code:

Code: Select all

ahk_exe omepro
But it does get a match because ahk_exe only says what it is but it is not part of it. If it was a part of it, why is it that SetTitleMatchMode RegEx behaves completely different regarding ahk_class?

This (in contrast to ahk_exe) works!

Code: Select all

ahk_class i)^someclass$
and this does not work (same as ahk_exe)

Code: Select all

i)^ahk_class someclass$
So I really did some testing and it may be that the behavior is different at your machine but at mine it is what it is and now tell me that it works correct; I don't think so.
However, I would really appreciate it if you could do some more testing and find out how AHK behaves with ahk_class at your PC.

Greetings Leli196
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 15:10

Run this code, save the information to Clipboard when asked and paste the information in a reply here so we can get information about your system and the version of AHK you're running:

Code: Select all

info :=	"AHK Version:`t" A_AhkVersion
		. "`nUnicode:`t`t" (A_IsUnicode ? "Yes " ((A_PtrSize=8) ? "(64-bit)" : "(32-bit)") : "No")
		. "`nOperating System:`t" (!A_OSVersion ? A_OSType : A_OSVersion)
		. "`nAdmin Rights:`t" (A_IsAdmin ? "Yes" : "No")
MsgBox, 68, Support Information, %info%`n`nWould you like to copy this information to the Clipboard?
IfMsgBox Yes
{
	Clipboard :=   info
	ClipWait
	MsgBox, The information was sent to the Clipboard.
}
return
Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 15:19

Sure, here it is:

Code: Select all

AHK Version:		1.1.23.05
Unicode:			Yes (64-bit)
Operating System:	WIN_7
Admin Rights:		Yes
Nevertheless it would be really nice to know whether it works with ahk_class the same way it does with ahk_exe at your system and whether this really is the way it is meant to work.

Greetings Leli196
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 15:38

Here's my test code using AutoHotkey Help as the target window (window ID and PID are hard coded):

Code: Select all

MsgBox %	"AutoHotkey Help found by:`n`n"
		 . "ahk_id 0xf0b8a:`t" (WinExist("ahk_id 0xf0b8a") ? "Pass" : "Fail") "`n"
		 . "ahk_pid 9412:`t" (WinExist("ahk_pid 9412") ? "Pass" : "Fail") "`n"
		 . "ahk_class HH Parent:`t" (WinExist("ahk_class HH Parent") ? "Pass" : "Fail") "`n"
		 . "ahk_exe hh.exe:`t" (WinExist("ahk_exe hh.exe") ? "Pass" : "Fail") "`n"
		 . "i)^ahk_id 0xf0b8a$:`t" (WinExist("i)^ahk_id 0xf0b8a$") ? "Pass" : "Fail") "`n"
		 . "i)^ahk_pid 9412$:`t" (WinExist("i)^ahk_pid 9412$") ? "Pass" : "Fail") "`n"
		 . "i)^ahk_class HH Parent$:`t" (WinExist("i)^ahk_class HH Parent$") ? "Pass" : "Fail") "`n"
		 . "i)^ahk_exe hh.exe$:`t" (WinExist("i)^ahk_exe hh.exe$") ? "Pass" : "Fail") "`n"
		 . "ahk_id i)^0xf0b8a$:`t" (WinExist("ahk_id i)^0xf0b8a$") ? "Pass" : "Fail") "`n"
		 . "ahk_pid i)^9412$:`t" (WinExist("ahk_pid i)^9412$") ? "Pass" : "Fail") "`n"
		 . "ahk_class i)^HH Parent$:`t" (WinExist("ahk_class i)^HH Parent$") ? "Pass" : "Fail") "`n"
		 . "ahk_exe i)^hh.exe$:`t" (WinExist("ahk_exe i)^hh.exe$") ? "Pass" : "Fail")
And here are the results:
---------------------------
test.ahk
---------------------------
AutoHotkey Help found by:

ahk_id 0xf0b8a: Pass
ahk_pid 9412: Pass
ahk_class HH Parent: Pass
ahk_exe hh.exe: Pass
i)^ahk_id 0xf0b8a$: Pass
i)^ahk_pid 9412$: Pass
i)^ahk_class HH Parent$: Pass
i)^ahk_exe hh.exe$: Pass
ahk_id i)^0xf0b8a$: Fail
ahk_pid i)^9412$: Fail
ahk_class i)^HH Parent$: Pass
ahk_exe i)^hh.exe$: Fail
---------------------------
OK
---------------------------
So I stand corrected, you may well have found a bug, but I don't think it's the bug you think it is. All strings have only one starting point, so (sans any modifiers) the circumflex can only work before the first character in the string. As you can see, every line but the ahk_class line fails when the circumflex is not in its proper position, just as they should. The fact that the ahk_class line didn't fail would seem to be the bug.
Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

14 Apr 2016, 17:36

Nice test code. When I run it on my system I get the same results.
So obviously you were right with how to properly use ahk_exe and ahk_class with regex and I was wrong.
But the i) and the circumflex have a purpose that is not quite taken into account so I have added a few lines that also test it when e.g. the i) option is active and instead of hh.exe there is HH.exe.

Here is the code:

Code: Select all

MsgBox %	"AutoHotkey Help found by:`n`n"
		. "ahk_id 0x7903fc:`t" (WinExist("ahk_id 0x7903fc") ? "Pass" : "Fail") "`n"
		. "ahk_pid 6228:`t" (WinExist("ahk_pid 6228") ? "Pass" : "Fail") "`n"
		. "ahk_class hh parent:`t" (WinExist("ahk_class hh parent") ? "Pass" : "Fail") "`n"
		. "ahk_exe HH.exe:`t" (WinExist("ahk_exe HH.exe") ? "Pass" : "Fail") "`n"
		. "ahk_id 903fc$:`t" (WinExist("ahk_id 903fc$") ? "Pass" : "Fail") "`n"
		. "ahk_pid 28$:`t" (WinExist("ahk_pid 28$") ? "Pass" : "Fail") "`n"
		. "ahk_class Parent$:`t" (WinExist("ahk_class Parent$") ? "Pass" : "Fail") "`n"
		. "ahk_exe h.exe$:`t" (WinExist("ahk_exe h.exe$") ? "Pass" : "Fail") "`n"
		. "`n"
		. "i)^ahk_id 0x7903fc$:`t" (WinExist("i)^ahk_id 0x7903fc$") ? "Pass" : "Fail") "`n"
		. "i)^ahk_pid 6228$:`t" (WinExist("i)^ahk_pid 6228$") ? "Pass" : "Fail") "`n"
		. "i)^ahk_class hh parent$:`t" (WinExist("i)^ahk_class hh parent$") ? "Pass" : "Fail") "`n"
		. "i)^ahk_exe HH.exe$:`t" (WinExist("i)^ahk_exe HH.exe$") ? "Pass" : "Fail") "`n"
		. "i)ahk_id 0x7903fc$:`t" (WinExist("i)ahk_id 0x7903fc$") ? "Pass" : "Fail") "`n"
		. "i)ahk_pid 6228$:`t" (WinExist("i)ahk_pid 6228$") ? "Pass" : "Fail") "`n"
		. "i)ahk_class hh parent$:`t" (WinExist("i)ahk_class hh parent$") ? "Pass" : "Fail") "`n"
		. "i)ahk_exe HH.exe$:`t" (WinExist("i)ahk_exe HH.exe$") ? "Pass" : "Fail") "`n"
		. "`n"
		. "^ahk_id 0x7903fc$:`t" (WinExist("^ahk_id 0x7903fc$") ? "Pass" : "Fail") "`n"
		. "^ahk_pid 6228$:`t" (WinExist("^ahk_pid 6228$") ? "Pass" : "Fail") "`n"
		. "^ahk_class HH Parent$:`t" (WinExist("^ahk_class HH Parent$") ? "Pass" : "Fail") "`n"
		. "^ahk_exe hh.exe$:`t" (WinExist("^ahk_exe hh.exe$") ? "Pass" : "Fail") "`n"
		. "^ahk_id 903fc$:`t" (WinExist("^ahk_id 903fc$") ? "Pass" : "Fail") "`n"
		. "^ahk_pid 28$:`t" (WinExist("^ahk_pid 28$") ? "Pass" : "Fail") "`n"
		. "^ahk_class Parent$:`t" (WinExist("^ahk_class Parent$") ? "Pass" : "Fail") "`n"
		. "^ahk_exe h.exe$:`t" (WinExist("^ahk_exe h.exe$") ? "Pass" : "Fail") "`n"
		. "`n"
		. "ahk_id i)^0x7903fc$:`t" (WinExist("ahk_id i)^0x7903fc$") ? "Pass" : "Fail") "`n"
		. "ahk_pid i)^6228$:`t" (WinExist("ahk_pid i)^6228$") ? "Pass" : "Fail") "`n"
		. "ahk_class i)^hh parent$:`t" (WinExist("ahk_class i)^hh parent$") ? "Pass" : "Fail") "`n"
		. "ahk_exe i)^HH.exe$:`t" (WinExist("ahk_exe i)^HH.exe$") ? "Pass" : "Fail") "`n"
		. "`n"
		. "ahk_id i)0x7903fc$:`t" (WinExist("ahk_id i)0x7903fc$") ? "Pass" : "Fail") "`n"
		. "ahk_pid i)6228$:`t" (WinExist("ahk_pid i)6228$") ? "Pass" : "Fail") "`n"
		. "ahk_class i)hh parent$:`t" (WinExist("ahk_class i)hh parent$") ? "Pass" : "Fail") "`n"
		. "ahk_exe i)HH.exe$:`t" (WinExist("ahk_exe i)HH.exe$") ? "Pass" : "Fail")
And here are the results with everything in green that (as far as I can tell) works as expected and everything in red that does not work properly. I left the color black if I was not quite sure btw.
The values of the window (by Window Spy)
ahk_class HH Parent
ahk_exe hh.exe
---------------------------
test.ahk
---------------------------
AutoHotkey Help found by:

ahk_id 0x7903fc: Pass
ahk_pid 6228: Pass
ahk_class hh parent: Fail
ahk_exe HH.exe: Fail
ahk_id 903fc$: Fail
ahk_pid 28$: Fail
ahk_class Parent$: Pass
ahk_exe h.exe$: Pass

i)^ahk_id 0x7903fc$: Pass
i)^ahk_pid 6228$: Pass
i)^ahk_class hh parent$: Fail
i)^ahk_exe HH.exe$: Fail
i)ahk_id 0x7903fc$: Fail
i)ahk_pid 6228$: Fail
i)ahk_class hh parent$: Fail
i)ahk_exe HH.exe$: Fail

^ahk_id 0x7903fc$: Pass
^ahk_pid 6228$: Pass
^ahk_class HH Parent$: Pass
^ahk_exe hh.exe$: Pass
^ahk_id 903fc$: Fail
^ahk_pid 28$: Fail
^ahk_class Parent$: Pass
^ahk_exe h.exe$: Pass

ahk_id i)^0x7903fc$: Fail
ahk_pid i)^6228$: Fail
ahk_class i)^hh parent$: Pass
ahk_exe i)^HH.exe$: Fail

ahk_id i)0x7903fc$: Fail
ahk_pid i)6228$: Fail
ahk_class i)hh parent$: Pass
ahk_exe i)HH.exe$: Pass
---------------------------
OK
---------------------------
So this seems to be quite ... weird! Or am I wrong with something?

Greetings Leli196
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

15 Apr 2016, 03:27

I haven't read the whole thread, but I'm pretty sure you both have the wrong expectations, possibly because the documentation is inaccurate.
SetTitleMatchMode wrote:Changes WinTitle, WinText, ExcludeTitle, and ExcludeText to be regular expressions.
Those parameters aren't regular expressions; rather, the title/text components of those parameters are.
SetTitleMatchMode wrote:RegEx also applies to ahk_class;
It only mentions ahk_class, not ahk_exe or any other keyword. However, on the WinTitle page ...
If the RegEx title matching mode is active, ahk_exe accepts a regular expression.
As it implies, the title, class and process path each take a regex pattern. For example, i)xxx ahk_class i)yyy is the correct way to specify case-insensitivity for each pattern.
sinkfaze wrote:Everything in the WinTitle field is the string upon which regex acts
No. That doesn't even make sense. The WinTitle field sets multiple criteria, and is what contains the regex pattern itself, not the string against which the pattern is matched. For the pattern to match over all criteria, AutoHotkey would first have to determine the pattern (%title% ahk_exe %process_name_or_path%) and then build a string matching that pattern for each and every window, and match that against the regex pattern. That would be a lot more work, and not particularly intuitive.

^ahk_id 0x7903fc$ and similar match because:
  • the WinTitle component ends at the first ahk_ keyword,
  • ^ (which is the entire title regex pattern) matches any string at all, and
  • For ahk_class and ahk_exe, $ matches at the end of the class/process path.
  • For numeric criteria such as ahk_pid, $ and other trailing non-numeric characters are ignored by whatever string->int conversion function is used (as is common for the C runtime functions).
Note that ^ahk_class someclass$ will also match xxxsomeclass, because the circumflex (^) is the complete title regex, not part of the class regex.
Leli196 wrote:; this does not work at all, no match
WinGet, window1_ID, ID, ahk_exe i)^SomeProg.exe$
In the RegEx mode, ahk_exe is matched against the full path of the process only. If you want to match the process name, you can just precede it with a slash (which must be escaped in RegEx mode).
Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

15 Apr 2016, 06:59

lexikos wrote:In the RegEx mode, ahk_exe is matched against the full path of the process only. If you want to match the process name, you can just precede it with a slash (which must be escaped in RegEx mode).
I still cannot figure this out. Could you please give an example of how the pattern has to look like with case insensitiveness and circumflex that match hh.exe if the pattern is HH.exe?

And shouldn't this work if ahk_pid etc. are not part of the string?

Code: Select all

ahk_pid i)^6228
Greetings Leli196
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

15 Apr 2016, 08:47

sinkfaze wrote: So this:

Code: Select all

i)^ahk_exe SomeProg.exe$
Is the correct way to use it, and I can successfully retrieve information from a window using ahk_exe in that manner.
there is no way that this is correct

edit/
hadn't read the whole thread, just saw Lex responded

Leli196 wrote:
lexikos wrote:In the RegEx mode, ahk_exe is matched against the full path of the process only. If you want to match the process name, you can just precede it with a slash (which must be escaped in RegEx mode).
I still cannot figure this out. Could you please give an example of how the pattern has to look like with case insensitiveness and circumflex that match hh.exe if the pattern is HH.exe?
circumflex matches at the start of the string. if Lex just told you that it matches against the full path, then clearly ^hh.exe isn't going to match the full path. just try to throw in some wildcards then. i)^.*hh.exe$

why do you care to use the circumflex anyway?

Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

15 Apr 2016, 09:52

Ah now I really understand what Lexikos wanted to tell when saying I could use a slah to only match the process name.
guest3456 wrote: why do you care to use the circumflex anyway?
Well, at the beginning I was just having a few issues and then I opened a thread in the help section. Nobody replied so I looked deeper into this and came to the conclusion that it does not work properly (I had no idea that it is matched against the whole path btw).
Sinkfaze told me ahk_exe is part of the string and the regex options have to go in front of it therefore. With this in mind he as well as myself did some further testing that resulted in my large post (post #7), leaving me completely confused.
So in the end I just wanted to know how to use regex in win title in the first place.

However, one question remains. Shouldn*t this find a matching window with the id 6228? (Of course i) and circumflex are unnecessary here.) Or is it because the regex mode is just not available for ahk_id and ahk_pid?

Code: Select all

ahk_pid i)^6228
Greetings Leli196
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

15 Apr 2016, 22:04

I already pointed out the parts of the documentation that tell you the title, text, ahk_class and ahk_exe accept regex patterns. There is nothing indicating the same for ahk_pid or ahk_id. Why would you ever use a regex pattern to match an arbitrary system assigned number? There is no discernable pattern to the numbers that would be of any use to a script.

So no, they do not support regex.
Leli196
Posts: 215
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

16 Apr 2016, 05:15

Okay, thank you very much for your help!
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

16 Apr 2016, 21:59

lexikos wrote:That doesn't even make sense.
But i)xxx ahk_class i)yyy does? That is counterintuitive to how most users would ever use regex anywhere else in the language. That at the very least needs a considerable amount of explanation in the documentation.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetTitleMatchMode RegEx does not work properly with ahk_exe

18 Apr 2016, 22:32

Yes. The title and other criteria are delimited by keywords. It is no different when regex is used.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 24 guests