c++ - 在 AHK 中使用下拉列表和 gui 文本框的条件行为

标签 c++ autohotkey

假设我选择“Option1”和“Color1”。然后我在自由文本区写一些东西。现在,当我按下 OK 时,它将执行条件标记。由于选择了 Option1/color1,它将使用以下命令执行发送输入命令:

blablala %text1% blabla %text2%.

但是,如果我选择“option1”和“color”,它将执行发送输入

blabla with his wife and her wife text1 then the dog did text2.

我已经完成了这段代码的一部分。我的问题是,当我从下拉列表中选择时,无论我写了什么,它都会执行脚本。我希望它在单击“确定”并在我想放置的任何位置显示 text1/text2 后执行。

#NoEnv
Gui, 1: font, s10 , Verdana
Gui, 1: Add, DropDownList, gDropDownList vDropDownList1 R2 choose1, Option1|Option2
Gui, 1: Add, DropDownList, gDropDownList vDropDownList2 R2 choose1, Color1|Color2
Gui, 1:Add, text,, Text1
Gui, 1:Add, edit, vText1
Gui, 1:Add, text,, Text2
Gui, 1:Add, edit, vText2
Return

DropDownList: 
Gui, 1:Submit,NoHide
if (dropdownlist1 = "Option1") && (dropdownlist2 = "Color1")
{
    MsgBox, A flower said to a be: %text1%. The bee replied %text2%
    Gui 1: hide
}
else if (dropdownlist1 = "Option1") && (dropdownlist2 = "Color2")
{    
    MsgBox, You picked %text1% and %text2%
    Gui 1: hide 
}
else if (dropdownlist1 = "Option2") && (dropdownlist2 = "Color1")
{    
    MsgBox, A girl said %text1% when you picked %text2%
    Gui 1: hide 
}
else if (dropdownlist1 = "Option2") && (dropdownlist2 = "Color2")
{    
    MsgBox, Blabla %text1% blabla %text2%
    Gui 1: hide 
}
return

#j::
Gui 1: show,, DropDownGui
return

最佳答案

I've managed todo part of this code. My problem is that when I pick from the droplists, it executes the script no matter what I wrote.

那是因为您在下拉列表中附加了一个 gosub。这就是 gDropDownList 中的 g 的含义。当您从中选择某些内容时,它会运行 DropDownList 标签。

您可以从选项字段中完全删除 gDropDownList,或者您可以制作一个标签,通过制作一个 gui 提交标签来保存您点击时的选择。

尝试这样的事情:

#NoEnv
Gui, 1:font, s10 , Verdana
Gui, 1:Add, DropDownList, gGuiSave vDropDownList1 R2 choose1, Option1|Option2
Gui, 1:Add, DropDownList, gGuiSave vDropDownList2 R2 choose1, Color1|Color2
Gui, 1:Add, text,, Text1
Gui, 1:Add, edit, vText1
Gui, 1:Add, text,, Text2
Gui, 1:Add, edit, vText2
Return

GuiSave:
    Gui, 1:Submit,NoHide
return

DropDownList: 
Gui, 1:Submit,NoHide
if (dropdownlist1 = "Option1") && (dropdownlist2 = "Color1")
{
    MsgBox, A flower said to a be: %text1%. The bee replied %text2%
    Gui 1: hide
}
else if (dropdownlist1 = "Option1") && (dropdownlist2 = "Color2")
{    
    MsgBox, You picked %text1% and %text2%
    Gui 1: hide 
}
else if (dropdownlist1 = "Option2") && (dropdownlist2 = "Color1")
{    
    MsgBox, A girl said %text1% when you picked %text2%
    Gui 1: hide 
}
else if (dropdownlist1 = "Option2") && (dropdownlist2 = "Color2")
{    
    MsgBox, Blabla %text1% blabla %text2%
    Gui 1: hide 
}
return

#j::
Gui 1: show,, DropDownGui
return

关于c++ - 在 AHK 中使用下拉列表和 gui 文本框的条件行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44189259/

相关文章:

click - 使用 AutoHotkey 单击窗口中的按钮

autohotkey - 在 AutoHotKey 的 IfWinNotActive 中排除两个 Windows

c++ - 在 C 中包装 C++ 成员函数 - Visual Studio 2013 模板问题

c++ - 实例化变量的新实例

c++ - DbgHelp.dll 是 Windows 内置的吗?我可以相信它在那里吗?

C++11 - 在编译时获取所有类变量并在没有 Boost 的情况下为它们调用方法

c++ - 如何使用 Bazel 获得 C++ 代码覆盖率?

autohotkey - 如何使我的反拖延脚本免受注销和关闭的影响?

automation - Inno Setup 可以发送按键和鼠标按下吗?如果没有,如何使用安装程序来完成此操作?

autohotkey - 如何检测 AutoHotKey 中的热键后的下一个按键