首页 > 解决方案 > 关闭 GUI 但继续 AHK 中的脚本

问题描述

我正在尝试关闭 gui,但让脚本继续运行。esc这是因为如果用户选择通过点击或简单地单击右上角的“X”来退出 GUI,我想执行其他操作。我不明白如何让脚本运行但关闭 gui。单击或 X 时,GUI 关闭似乎没有做任何事情esc。我已经扫描了GUI文档,但无法弄清楚。他们总是运行exitapp,但我还没准备好exitapp,我需要做其他事情。

Gui, Add, Text, ,To cancel, press ESCAPE or close this window.

Gui, Show, w320 h80, Downloads

GuiClose:
GuiEscape:
; Continue on to do other things here!!!!
WinActivate ahk_exe notepad++.exe
; do things...
exitapp

标签: autohotkey

解决方案


你所描述的听起来就像我想做的一样。这是很多艰难和零碎的工作,但我认为您正在寻找的是Gui, Cancel看看下面的代码,看看这是否不能解决您的问题。

ExitApp如果您想稍后弹出它,它不会使用并且不会破坏窗口。您必须弄清楚如何放置其余代码,但我相信这就是您要问的。

;Set the GUI window
Gui, Add, Text,, Hit Escape to Clear window when it is active

#F9:: ;show the window with WindowsKey-F9 
Gui, Show, 
return

;set the escape key to clear GUI window
GuiEscape: ; Note: single colon here, not double
Gui, Cancel
Return

如果您有多个 GUI 窗口,那就有点棘手了。您必须命名每个:

;Set the two GUI windows. In example, First is labeled as FirstGUI and second as SecondGUI. Notice how you separate with single colon.
Gui, FirstGUI:Add, Text,, Hit Escape to Clear FirstGUI window when it is active
Gui, SecondGUI:Add, Text,, Hit Escape to Clear SecondGUI window when it is active

#F9:: ;show the two windows ("xCenter y700" is used to prevent the windows from stacking.)
Gui, FirstGUI:Show, xCenter y700, Window Title of First GUI
Gui, SecondGUI:Show, xCenter y900, Window Title of Second GUI
return

;set the escape key to clear for each Gui independently. 

FirstGUIGuiEscape: ; Note that you must add the Gui Name (FirstGUI) to the beginning of the "GuiEscape:" command and also name it in the following:
Gui, FirstGUI:Cancel
Return

SecondGUIGuiEscape: ; And here you must add SecondGUI as noted above.
Gui, SecondGUI:Cancel
Return

回答有点晚,但希望这对您或其他人有用!


推荐阅读