AHK 阻止单选按钮执行操作

AHK prevent radio button from executing action

提问人:Neelfinity 提问时间:11/3/2023 更新时间:11/3/2023 访问量:44

问:

日安

我正在尝试为 AutoHotKey (AHK) 创建脚本。脚本本身已经运行良好,但我的问题是,在 GUI 中,当我按下单选按钮或复选框(“颜色”和“选项”GroupBox)时,它会自动执行函数的操作(在本例中为“组合”),但我只想选择选项,并且只能通过按底部的“Enter”按钮来切换功能。

下面是 GUI:

enter image description here

脚本如下:

#SingleInstance Force

Gui, Main:new

Gui, Add, GroupBox, x10 y6 w150 h100 R3, Color:
Gui, Add, Radio, Checked        vColor1     gCombo xp+10 yp+20,     Black
Gui, Add, Radio,                vColor2     gCombo,                 White
 
Gui, Add, GroupBox, x10 w150 h100 R3, Option:
Gui, Add, CheckBox,             vOption2   gOption2 xp+10 yp+20,  Option 2
Gui, Add, CheckBox, Checked     vOption1   gOption1,              Option 1

Gui, Add, Button, gEnter xp-11 yp+42, Enter

Gui, Show
return

Enter:
    gosub Combo
    Gui, Hide
return

Combo:
    Gui, Submit, NoHide
    if ((Color1=1)&(Option2=0)&(Option1=0)){
        MsgBox, PLEASE CHOOSE OPTION
    }
    else if ((Color1=1)&(Option2=1)&(Option1=0)){
        gosub Option2
    }
    else if ((Color1=1)&(Option2=0)&(Option1=1)){
        gosub Option1
    }
return

GuiClose:
    Gui, Main:Destroy
ExitApp

Option2:
    MsgBox, You have chosen Option 2
return

Option1:
    MsgBox, You have chosen Option 1
return

解决方案可能没有那么复杂,但我不知道如何解决它。

复选框 单选按钮 自动热键

评论


答:

1赞 Dieisson Silva dos Santos 11/3/2023 #1

这应该可以帮助您:

#SingleInstance Force

Gui, Add, GroupBox , x10 y6 w150 h100 R3, Color:
Gui, Add, Radio, Checked        vColor1   xp+10 yp+20,   Black
Gui, Add, Radio,                vColor2  ,               White
 
Gui, Add, GroupBox , x10 w150 h100 R3, Option:
Gui, Add, CheckBox,          vOption2   xp+10 yp+20,  Option 2
Gui, Add, CheckBox , Checked     vOption1   ,             Option 1

Gui, Add, Button, gEnter xp-11 yp+42, Enter

Gui, Show
return

Enter:

    Gui, Submit, NoHide

    Switch  {

        Case !option1 && !option2:
            MsgBox, PLEASE CHOOSE OPTION

        Case Color1 && Option2 && !Option1:
            MsgBox, Color 1 and option 2 selected

        Case Color1 && !Option2 && Option1:
            MsgBox, Color 1 and option 1 selected

        Case Color1 && Option2 && Option1:
            MsgBox, Color 1, option 1 and option 2 selected

        Case Color2 && Option2 && !Option1:
            MsgBox, Color 2 and option 2 selected

        Case Color2 && !Option2 && Option1:
            MsgBox, Color 2 and option 1 selected

        Case Color2 && Option2 && Option1:
            MsgBox, Color 2, option 1 and option 2 selected

    }

return

GuiClose:
    ExitApp

评论

1赞 Neelfinity 11/3/2023
非常感谢你@Dieisson,它完全符合我的要求!