每次打开记事本 window 时显示 GUI

Show the GUI every time the Notepad window is opened

我正在尝试创建代码,每次打开记事本时都会显示 foo window。问题是,如果我关闭 foo 一次,它将不会再次显示(当我下次打开记事本时)。目前我正在使用以下代码:

SetTitleMatchMode, 2
WinWaitActive, Notepad
Gui, Add, Button, w200 h25 gTest1 , button 1
Gui, Add, Button, w200 h25 gTest2 , button 2
Gui, Show,, foo
Return

Test1:
Run test1.ahk
Return

Test2:
Run test2.ahk
Return
#Persistent

Gui, Add, Button, w200 h25 gTest1 , button 1
Gui, Add, Button, w200 h25 gTest2 , button 2

SetTimer, Show_Gui, 300
return

Show_Gui:
IfWinNotExist, ahk_class Notepad
{
    Gui, cancel
    return
}
; Otherwise:
SetTimer, Show_Gui, off
Gui, Show,, foo
WinWaitClose, ahk_class Notepad
SetTimer, Show_Gui, on
Return

Test1:
; do sth
return

Test2:
; do sth
return

https://autohotkey.com/docs/commands/SetTimer.htm#Examples