SetTitleMatchMode issue Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

SetTitleMatchMode issue

Post by morreo » 27 Jan 2023, 12:51

Hello,

I found a bug in my script where 2 windows of similar names were being called by WinActivate based on which window I clicked on last before running the script. I isolated the line of code that was having the issue and tried using SetTitleMatchMode to solve it, however when using setting 3 (exact match), it's not identifying either of the windows (I thought it would identify 1 window). When I use setting 1 or 2, it identifies both windows (as expected)

I'm looking for a window called 5YR-TNOTE MAR23. I have used windows spy to confirm this is the Window Title.
image.png
image.png (994 Bytes) Viewed 309 times
I also have a window called 5YR-TNOTE vs 10YR-TNOTE F IPS MAR23. According to Window Spy, they both have the same exact ahk_class, ahk_exe and ahk_pid, so SetTitleMatchMode seems like the best solution in this case.

Any idea why the exact match isn't picking up anything? Could the variable be affecting it?

Code: Select all

global globalTsysMonth := MAR23

+r::
	SetTitleMatchMode, 3
    WinActivate, 5YR-TNOTE %globalTsysMonth%
return

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: SetTitleMatchMode issue  Topic is solved

Post by Hellbent » 27 Jan 2023, 13:19

Try putting quotes around MAR23.

Code: Select all

global globalTsysMonth := "MAR23"

+r::
	SetTitleMatchMode, 3
    WinActivate, 5YR-TNOTE %globalTsysMonth%
return
This is what your code was doing.

Code: Select all

Mar23 := "As you can see, Mar23 is a variable"
global globalTsysMonth := MAR23

+r::
    msgbox, 5YR-TNOTE %globalTsysMonth%
return

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: SetTitleMatchMode issue

Post by morreo » 27 Jan 2023, 13:27

Wow, I'll have to keep that in mind when using Strings as variables.

Thank you

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: SetTitleMatchMode issue

Post by Hellbent » 27 Jan 2023, 13:42

You can also do it with the = operator instead of the := operator but it is better to just use the expression operator when you can.

Code: Select all


;This works: 
global globalTsysMonth = MAR23 ;( String literal syntax )

;And so does this: ( better to do it this way )
global globalTsysMonth := "MAR23"  ;( Expression syntax )

+r::
	SetTitleMatchMode, 3
    WinActivate, 5YR-TNOTE %globalTsysMonth%
return

Post Reply

Return to “Ask for Help (v1)”