在没有按下X按钮的情况下,AutoHotkey在GuiClose之后执行命令

时间:2017-10-29 17:08:00

标签: user-interface autohotkey

我的目标是使用我学到的知识来制作带有三个按钮的GUI来打开相应的.ahk文件。到目前为止,我的代码完全正常,直到我关闭GUI时添加代码以关闭脚本。当我添加此代码时......

GuiClose: 
    ExitApp
    return

到顶部,它使脚本在运行后立即关闭。但是,如果按下GUI上的X按钮,我只想运行那些代码。我在这里缺少什么?

我的所有代码:

#SingleInstance, force

GuiClose: 
    ExitApp
    return

Gui, Add, Button, y0 x0 w32 h32 g1, 1
Gui, Add, Button, y0 x45 w32 h32 g2, 2
Gui, Add, Button, y0 x90 w32 h32 g3, 3
Gui, Show, x800 y50 w150 h100, The Gui
return

1:
    run, open "C:\users\Milquetoast\Desktop\learned.ahk"
    return

2:
    run, open "C:\users\Milquetoast\Desktop\learned2.ahk"
    return

3:
    run, open "C:\users\Milquetoast\Desktop\learned3.ahk"
    return

1 个答案:

答案 0 :(得分:0)

auto-exection section (=第一个热键,热字符串,返回,OnMessage或GUI定义之前的脚本顶部)会自动执行脚本启动

因此,您无法在此部分中定义 label (子例程)。

#SingleInstance, force

Gui, Add, Button, y0 x0 w32 h32 g1, 1
Gui, Add, Button, y0 x45 w32 h32 g2, 2
Gui, Add, Button, y0 x90 w32 h32 g3, 3
Gui, Show, x800 y50 w150 h100, The Gui

        RETURN   ; === end of auto-execute section ===

1:
    run, C:\users\Milquetoast\Desktop\learned.ahk
return

2:
    run, C:\users\Milquetoast\Desktop\learned2.ahk
return

3:
    run, C:\users\Milquetoast\Desktop\learned3.ahk
return

GuiClose: 
    ExitApp
return