【问题标题】:Use Enter button for submit, while working normally elsewhere使用 Enter 按钮提交,而在其他地方正常工作
【发布时间】:2020-11-26 03:05:40
【问题描述】:

我有一个脚本,它打开一个带有简单界面的 GUI,用 Esc 关闭,然后通过按钮提交。该脚本始终在后台运行。我正在尝试找到一种方法使 Enter 键作为提交工作,但在其他任何地方仍然正常工作。我试过使用 IfWinActive,但它不起作用。有任何想法吗?谢谢! (顺便说一下,有些代码在这种格式下看起来很乱,但是因为这不是完整的脚本,所以存在“不必要的细节”。)

Lwin & MButton::
Goto, Start
return


Start:
IfWinNotExist, New
{
    Gui,1:-border
    gui, font, s24, Product Sans  ; Set 10-point Product Sans.
    Gui, Add, Text,, Type here to search:                                      ;controls the UI
    Gui, Add, Edit, vTextInput
    Gui, Add, Button, -WantReturn gSubmit w80, Go
    Gui, Show, w400 h300, New
    IfWinExist, New
    Hotkey, Enter, Submit, On
    return
}
Else
Return

IfWinExist, New
Esc::Gui, Destroy
return

IfWinExist, New
Enter::
Goto, Submit
return



Submit:
Gui, Submit                          ;destroys the UI when submitted
GuiControlGet, TextInput
Gui, Destroy

Else
{
    link = https://www.google.com/search?q= %TextInput%                            ;search google 
    Run, %link%
}

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    代码看起来真的很恐怖哈哈。
    这么多遗留的 AHK 或不起作用的东西。但无论如何,由于这不是完整的脚本,因此无法解决所有问题。

    实际问题的答案是将您的按钮设为default button:

    Gui, -Border
    Gui, Font, s24, % "Product Sans"
    Gui, Add, Text, , % "Type here to search:"
    Gui, Add, Edit, vTextInput
    Gui, Add, Button, +Default gSubmit w80, % "Go"
    Gui, Show, w400 h300, % "New"
    return
    
    Submit:
        Gui, Submit
        Run, % "https://www.google.com/search?q=" TextInput
    return
    

    当然,您也可以定义自己的热键,就像您尝试过的那样,但是没有理由让上面这么方便。

    【讨论】:

    • 谢谢!是的,我认为这会是一团糟,因为我至少有一年没有更新我的脚本了,哈哈哈。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 2014-07-20
    • 1970-01-01
    • 2016-10-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多