SetTitleMatchMode not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

SetTitleMatchMode not working

08 Jan 2021, 05:22

In the script I first use

Code: Select all

SetTitleMatchMode, RegEx
, then command

Code: Select all

SetTitleMatchMode, 2
, but only the one that comes first works.
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 06:33

Below is my working example with Notepad.

Code: Select all

SetTitleMatchMode, RegEx
SetTitleMatchMode, 2
WinActivate, .otepad
For many windows, both statements will yield a match. This depends on the specific string. Feel free to provide your example.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 07:05

Code: Select all

SetTitleMatchMode, RegEx
Numpad2::
IfWinActive ^.*Browse.*$
Send 1
Return
and

Code: Select all

SetTitleMatchMode, 2
Numpad3::
WinGet, ExStyle, ExStyle, ahk_exe mpv.exe
If (ExStyle & 0x8)
winSet, alwaysOnTop, toggle, a
Send {LCtrl Down}{LShift Down}{LAlt Down}{LWin Down}{scB}{LCtrl Up}{LShift Up}{LAlt Up}{LWin Up}
retur
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 07:09

Is that supposed to be one script rather than two?

What is your window title, and what problem are you seeing?

The match mode of 2 would not relate to ahk_exe, right? It applies to title text.

Your WinSet and Send commands act upon the active window. If mpv is not active, then your commands will not act on it.

Multi-line hotkey routines should end in Return.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 07:33

mikeyww
These are two scripts for different windows. SetTitleMatchMode, RegEx relate to ^.*Browse.*$, SetTitleMatchMode, 2 relate to ahk_exe mpv.exe respectively.

Code: Select all

SetTitleMatchMode, RegEx
Numpad2::
IfWinActive ^.*Browse.*$
Send 1
Return

SetTitleMatchMode, 2
Numpad3::
WinGet, ExStyle, ExStyle, ahk_exe mpv.exe
If (ExStyle & 0x8)
winSet, alwaysOnTop, toggle, a
Send 2
Return
Last edited by reluct on 08 Jan 2021, 07:44, edited 1 time in total.
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 07:44

What is your window title, and what problem are you seeing? A description beyond "only the one that comes first works" will be helpful. Can you provide more details?
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 07:53

The problem is that if I use this code

Code: Select all

SetTitleMatchMode, RegEx
Numpad2::
IfWinActive ^.*Browse.*$
Send 1
Return

SetTitleMatchMode, 2
Numpad3::
WinGet, ExStyle, ExStyle, ahk_exe mpv.exe
If (ExStyle & 0x8)
winSet, alwaysOnTop, toggle, a
Send 2
Return
then only this part works

Code: Select all

SetTitleMatchMode, RegEx
Numpad2::
IfWinActive ^.*Browse.*$
Send 1
Return
If I swap blocks

Code: Select all

SetTitleMatchMode, 2
Numpad3::
WinGet, ExStyle, ExStyle, ahk_exe mpv.exe
If (ExStyle & 0x8)
winSet, alwaysOnTop, toggle, a
Send 2
Return

SetTitleMatchMode, RegEx
Numpad2::
IfWinActive ^.*Browse.*$
Send 1
Return
then only this part works

Code: Select all

etTitleMatchMode, 2
Numpad3::
WinGet, ExStyle, ExStyle, ahk_exe mpv.exe
If (ExStyle & 0x8)
winSet, alwaysOnTop, toggle, a
Send 2
Return
But never work both.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 08:04

window title 1 ^.*Browse.*$
window title 2 ahk_exe mpv.exe
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 08:05

Commands between hotkey routines are "unreachable" and will be ignored. :arrow: Auto-execute

Code: Select all

Numpad3::
WinGet, style, ExStyle, ahk_exe mpv.exe
If (style & 0x8)
 WinSet, AlwaysOnTop,, A
Send 2
Return

Numpad2::
SetTitleMatchMode, RegEx
If WinActive("^.*Browse.*$")
 Send 1
Return
Demonstration is below. What do you predict will happen?

Code: Select all

Numpad3::
Return

MsgBox, TEST

Numpad2::
Return
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 08:26

So what's the solution?
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working  Topic is solved

08 Jan 2021, 08:26

Code: Select all

Numpad3::
WinGet, style, ExStyle, ahk_exe mpv.exe
If (style & 0x8)
 WinSet, AlwaysOnTop,, A
Send 2
Return

Numpad2::
SetTitleMatchMode, RegEx
If WinActive("^.*Browse.*$")
 Send 1
Return
Or:

Code: Select all

Numpad3::
WinGet, style, ExStyle, ahk_exe mpv.exe
If (style & 0x8)
 WinSet, AlwaysOnTop,, A
Send 2
Return

Numpad2::
SetTitleMatchMode, 2
Send % WinActive("Browse") ? "1" : ""
Return
Or:

Code: Select all

SetTitleMatchMode, 2

Numpad3::
WinGet, style, ExStyle, ahk_exe mpv.exe
If (style & 0x8)
 WinSet, AlwaysOnTop,, A
Send 2
Return

Numpad2::Return
#IfWinActive Browse
Numpad2::Send 1
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 08:52

Hmm, it works. I thought with SetTitleMatchMode unspecified this code doesn't work. Is WinTitle what is written at the very top of the window?
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 08:57

Yes.
Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).
The ahk_exe format does not require setting the match mode.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 09:10

But what solution if in the future you may need two different SetTitleMatchMode?
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 10:03

The solution is shown in my examples. You put the Set command inside the hotkey routine if it is specific for that routine.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

08 Jan 2021, 11:08

mikeyww
Well, thanks for your help, I can't say that I understood everything, but I grasped some important points.
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

08 Jan 2021, 11:33

My script is similar to your original one, with the following changes.

1. Move Set command inside the hotkey routine.
2. Omit Set command for ahk_exe format, because you don't need it there.
3. If you just want to check for a single word in the window title, although RegEx works, match mode 2 also works and is simpler.

That's it. My script otherwise matches yours.

#IfWinActive is a way to limit the hotkey to the condition of whatever active window you specify. I used it in the last example to limit the hotkey to "Browse" as the active window title. The match mode is provided at the top of the script.
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

09 Jan 2021, 02:36

mikeyww
Why doesn't this script activate window ^.*Engvidshortcut.*$, ?

Code: Select all

Numpad1:: ; 1 F9 sc43
SetTitleMatchMode, RegEx
IfWinNotActive ahk_exe anki.exe
{
	Send, {sc41} ; F7
	Sleep 10
	Send, {Space}
	Return
}
else
{
	WinActivate, ^.*Engvidshortcut.*$
}
Return
User avatar
mikeyww
Posts: 27254
Joined: 09 Sep 2014, 18:38

Re: SetTitleMatchMode not working

09 Jan 2021, 06:23

Question #1: What is the complete window title of that window, as displayed at the top of Window Spy?

Question #2: What window is active when you trigger the hotkey?
reluct
Posts: 134
Joined: 28 Nov 2018, 05:07

Re: SetTitleMatchMode not working

09 Jan 2021, 08:14

1 Engvidshortcut - Anki
There is no mistake in the title. This script activates the window

Code: Select all

Numpad1:: ; 1 F9 sc43
SetTitleMatchMode, RegEx
IfWinNotActive ahk_exe anki.exe
{
 WinActivate, ^.*Engvidshortcut.*$
}
Return
2 Any window. Desktop.
But if you add a command after the WinActivate, ^.*Engvidshortcut.*$, then it will be executed.

Code: Select all

Numpad1:: ; 1 F9 sc43
SetTitleMatchMode, RegEx
IfWinNotActive ahk_exe anki.exe
{
	Send, {sc41} ; F7
	Sleep 10
	Send, {Space}
	Return
}
else
{
	Sleep 100
	WinActivate, ^.*Engvidshortcut.*$
	Sleep 500
	Send, {scA} 
	Sleep 500
	Send 1	
}
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], CoffeeChaton, GEOVAN and 171 guests