【问题标题】:Multiple GUIs not launching from AutoHotKey多个 GUI 未从 AutoHotKey 启动
【发布时间】:2015-03-24 03:33:00
【问题描述】:

我正在尝试自动化生成模板以向我们的外包提供商请求体检的过程。脚本中有六个 GUI:

  • 特别说明
  • 列出即将到来的约会
  • 联系方式
  • 列出的授权书?
  • 电子文件还是硬拷贝文件?
  • 授权号和生效日期范围

每个 GUI 都会要求用户选择一个或另一个,然后根据答案在模板中粘贴一段文本。

特殊指令的第一个 GUI 运行良好。但是脚本没有继续执行第二个 GUI,而是结束了。我使用 SciTE4 编辑器尝试查看发生了什么,在第一个 GUI 运行后,它跳到最后。

这是前两个 GUI 和结尾的代码:

;SPECIAL INSTRUCTIONS GUI
;Gui, Add, Text, W400 H40, Special instructions?
Gui, Add, Radio, vSpecInstrs Checked, Yes
Gui, Add, Radio, , No
Gui, Add, Edit, W370 r4 vListofInstrs, 
Gui, Add, Button, vButtonNext1 gNextSelected1, Next
Gui, Add, Button, xp+60 vButtonCancel1 gCancelSelected1, Cancel
Gui, Show, W400 H150, Special Instructions?
return
;

NextSelected1:
Gui, Submit, ; Save the input from the user to each control's associated variable.
If SpecInstrs = 1 
{
  SendInput >{space 2}>{space 2}>{space 2}>{space 2}>{space 2}IMPORTANT{!}{space 2}<{space 2}<{space 2}<{space 2}<{space 2}<
  Send {Enter 2}
  SendInput %ListofInstrs%
  Send {Enter 2}
  }
Else If SpecInstrs = 2
  {
  Send {Enter 2}
  }
SpecInstrs = 0
FileType = 
Gui, Destroy
;Return
;
; Actions on Cancel or Close
;
CancelSelected1:
;GuiClose:
;ExitApp
gosub, GuiClose
;Return

;UPCOMING APPOINTMENTS GUI
Gui, Add, Text, Center W200 H50, UPCOMING APPOINTMENTS?
Gui, Add, Radio, vAppts checked, Yes
Gui, Add, Radio, , No
Gui, Add, Button, vButtonNext2 gNextSelected2, Next
Gui, Add, Button, xp+60 vButtonCancel2 gCancelSelected2, Cancel
Gui, Show, , Appointments
return
;

NextSelected2:
Gui, Submit, ; Save the input from the user to each control's associated variable.
If Appts = 1
  {
  SendInput >{space 2}>{space 2}>{space 2}>{space 2}>{space 2}Future  Appointments - Do NOT Schedule On This Date{(}s{)}{space}<{space 2}<{space 2}<{space 2}<{space 2}<
  Send {Enter 2}
  SendInput {[}Copy and paste appointments from CPRS here{]} 
  Send {Enter 2}
  SendInput >{space 2}>{space 2}>{space 2}>{space 2}>{space 2}<{space 2}<{space 2}<{space 2}<{space 2}<
  Send {Enter 2}    
  }
Else If Appts = 2
  {
  Send Appointments pending:  None 
  Send {Enter 2}
  }
Gui, Destroy
Appts = 0  
Return
;
; Actions on Cancel or Close
;
CancelSelected2:
gosub, GuiClose
;GuiClose:
;ExitApp
Return

代码实际上永远不会到达即将到来的约会 GUI。在运行调试器时,在我选择 Next 按钮后,它会跳到最后的代码:

;
;
GuiClose:
  ExitApp
Return

我会粘贴其余的代码,但我想如果我能弄清楚如何让 GUI 2 在 GUI 1 之后运行,我可以让其他代码工作。 (此外,如果我什至无法运行 GUI 2,谁在乎其余的?!)。感谢您的帮助!

【问题讨论】:

  • NextSelected1 之后的returnCancelSelected1 之前)丢失/注释掉了,这意味着当你按下ButtonNext1 时,gosub, GuiClose 也会被执行
  • 不幸的是,这没有帮助。我从 NextSelected1 部分的 Return 中删除了分号,但只有第一部分执行,无论我检查是(粘贴在模板的第一部分中)还是否(两个 Enter/CR 为下一步留出空间) .
  • 请考虑更新问题startpost,这样我们才能真正重现您的问题。另外,代码之前已经过时了——在你的代码中,没有GuiClose这样的标签,只是注释掉了3次
  • 我只是将那些 GuiClose 的东西留在“以防万一”中,这些并不是我曾经认为的问题。简单地删除它们可能会更整洁。

标签: user-interface autohotkey


【解决方案1】:

您似乎对return 关键字存在重大误解: AutoHotkey 开始执行脚本的顶部直到第一个return 出现。之后,只有热键、热字符串、函数,最重要的是,标签可能会随之而来。

一些随机的 AutoHotkey 脚本可能如下所示:

#noEnv
sendMode, Input
setWorkingDir, %A_WorkingDir%
Gui, 1:add, button, gbuttonpressed, press me
Gui, 1:show
return

; any random commands here will never be executed, if not enclose in a labe, hotkey etc!

buttonpressed:
gui, 1:destroy
msgbox, hi!
goSub, secondGui_start
return

secondGui_start:
Gui, 2:add, text,, this Gui will show after the first one
Gui, 2:show
return

2GuiClose:
exitApp
return

回到你的脚本。

当按下带有关联变量ButtonNext 的按钮时,将调用标签NextSelected1。它以

结尾
Gui, Destroy
Return

,但你希望之后会发生一些事情!所以告诉编译器你想在return 之前进入下一个 Gui。否则,脚本将空闲,并且由于您既没有热键、热字符串也没有附加 #persistent 关键字,脚本将终止。

使用GoTo 关键字执行此操作。如果您将第二个 gui 放在自己的标签中,则可以这样调用。

最后,如果您想管理多个 gui,请对它们进行编号,就像我在上面的示例中所做的那样。

【讨论】:

  • 谢谢!我明天试试这个!它确实解释了一些事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-21
相关资源
最近更新 更多