Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Do I have to put `SetTitleMatchMode` on top of the script?

Writer Emily Wong

Sample script:

#NoEnv
#Warn
#SingleInstance Force
#IfWinActive Foo ahk_exe foo.exe !A::Send Foo
SetTitleMatchMode Regex
#IfWinActive Bar$ ahk_exe bar.exe !A::Send Bar

When running it, it throws:

enter image description here

I want to apply SetTitleMatchMode Regex only to bar.exe, is it achievable without putting it on top of the script?

1 Answer

I don't understand your script, but the answer is that you don't have to place it at the top. It will affect all following commands until a return.

Proof of concept script:

F1:: MsgBox, This should give 1`nA_TitleMatchMode=%A_TitleMatchMode% SetTitleMatchMode, 2 MsgBox, This should give 2`nA_TitleMatchMode=%A_TitleMatchMode% SetTitleMatchMode, regex MsgBox, This should give regex`nA_TitleMatchMode=%A_TitleMatchMode%
return
F2:: MsgBox, This should give 1`nA_TitleMatchMode=%A_TitleMatchMode%
return

To be convinced, run the above and press consecutivelyF2, F1, F2.

Each key-press starts a new thread, so SetTitleMatchMode is re-initialized to 1.


SetTitleMatchMode is redundant. Your code should look like (I didn't test):

#NOEnv
#Warn
#SingleInstance Force
SetTitleMatchMode Regex
!A::
if WinActive("Foo ahk_exe foo.exe") MsgBox, Foo
if WinActive("Bar$ ahk_exe bar.exe") MsgBox, Bar
11

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy