【问题标题】:How can an AutoHotkey GUI handle the {Return} key without using a default button?AutoHotkey GUI 如何在不使用默认按钮的情况下处理 {Return} 键?
【发布时间】:2012-11-06 02:15:57
【问题描述】:

我正在使用 AutoHotkey GUI + ListBox 从各种选项中选择一个选项,但我无法找到一种方法来让 RETURN 键关闭 GUI,而无需创建带有关联 ButtonOk 事件的附加默认按钮。这是我使用默认按钮的代码:

Gui, +LastFound +AlwaysOnTop -Caption   
Gui, Add, ListBox, vMyListBox gMyListBox w300 r10
Gui, Add, Button, Default, OK

GuiControl,, MyListBox, Option 1
GuiControl,, MyListBox, Option 2
GuiControl,, MyListBox, Option 3

Gui, Show
return

MyListBox:
if A_GuiEvent <> DoubleClick
    return

ButtonOK:
    GuiControlGet, MyListBox
    Gui Hide
    MsgBox %MyListBox% selected!
    ExitApp

GuiClose:
GuiEscape:
ExitApp

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    您可以使用the Hotkey command 在 GUI 可见时临时启用 Return 作为热键,并在 GUI 关闭时禁用它。

    【讨论】:

      【解决方案2】:

      您可以监视 WM_KEYDOWN 消息。在自动执行部分:

      OnMessage(0x100, "OnKeyDown")
      

      然后在脚本的其他地方:

      OnKeyDown(wParam)
      {
          if (A_Gui = 1 && wParam = 13) ; VK_ENTER := 13
          {
              GuiControlGet, MyListBox
              Gui Hide
              MsgBox %MyListBox% selected!
              ExitApp
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-10-21
        • 2015-10-02
        • 1970-01-01
        • 2021-07-16
        • 2012-03-15
        • 2011-01-01
        • 2018-03-03
        • 1970-01-01
        • 2011-08-01
        相关资源
        最近更新 更多