【问题标题】:AutoHotKey - "Continue" and "Cancel" ButtonsAutoHotKey - “继续”和“取消”按钮
【发布时间】:2014-12-10 10:05:03
【问题描述】:

我是 AutoHotKey 的新手,到目前为止,我认为自己很幸运能够创建一个脚本来自动化窗口中大约 90% 的数据输入。我现在正试图将它提升一个档次,并在我的数据输入脚本中添加一个警告/警告 GUI。我想暂停正在运行的脚本并打开一个 GUI,它会提醒我查看已经输入的内容,如果某个特定条目看起来不错,一个按钮可以让事情继续进行,另一个按钮可以从 GUI 和如果输入不正确,则脚本的其余部分。

这是我想出的一些代码,混合了一些伪代码来帮助显示我想要做什么。

(Previous data entry script executes to this point)
Stop the script
Gui, New
Gui, Add, Text, 'n Check Authorization Number to be sure it is A1234 (FY 15). ; Wraps text
Gui, Add, Button, Default, Continue
Gui, Add, Button, Quit
Gui, Show, IMPORTANT!
If Continue button is clicked
----Continue with script
If Abort button is clicked
----Close the GUI
----Exit the entire script (Resume where I left off with rest of the data entry script)

我已经阅读了 AHK 帮助文件,对如何使这些按钮起作用,以及如果我点击继续,如何正确地从 GUI 返回脚本,或者如果我发现问题。我可以调整诸如 GUI 的大小和按钮位置之类的东西;最重要的是让 GUI 代码正确。有人可以帮忙写代码吗? (我最后一次上编程课是在 2003 年,所以我已经忘记了很多!)

【问题讨论】:

    标签: user-interface button autohotkey


    【解决方案1】:

    在您的情况下,GUI 将是矫枉过正。 AHK(以及许多其他语言)为简单的用户交互提供标准对话框,称为消息框
    Message boxes in AHK 可以通过两种方式显示:

    1. MsgBox, This is a simple message. Please click "OK".
    2. MsgBox, 4, Attention, Here`, you can choose between "Yes" and "No".

    在第二种情况下,我们声明了一个选项来控制显示的按钮。您可以使用IfMsgBox 来检测用户点击了什么:

    IfMsgBox, Yes
        MsgBox, 4, Really?, Did you really mean "Yes"?
    

    将这些部分放在一起,我们可以让用户决定是否要继续,而无需创建 GUI,只需几行:

    ; Option "1" is "OK/Cancel"
    MsgBox, 1, IMPORTANT!,  Check Authorization Number to be sure it is A1234 (FY 15).
    IfMsgBox, Cancel
    {
        ExitApp
    }
    ; do stuff
    

    此代码也解决了您的其他每个问题:
    消息框会暂停当前线程,直到用户关闭对话框或它超时(如果您明确声明了超时)。
    为了完全停止我们的脚本的执行,我们使用ExitApp

    【讨论】:

    • 谢谢!我将在今天晚些时候尝试一下,然后告诉你结果如何。
    • 我一直很喜欢你有文化的 AHK 答案。 +1。 :)
    猜你喜欢
    • 2022-06-10
    • 2018-10-28
    • 2012-02-18
    • 2018-01-26
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多