如何在 AHK 的 GuiControl 命令中放置三元运算符?

问题描述 投票:0回答:1

我正在尝试制作一个表单屏幕,在以下情况下重置所有字段 单击“添加”或“编辑”按钮。每当运行该函数时,我想获取所选行的行值。当我单击“添加”按钮时,我想重置所有字段。当我单击“编辑”时,我希望当前选定的行为

RowValue
。不过,第一步是让这项工作发挥作用。这是我的代码:

    ; The function with the code
SetGui(Name, RowValue=0) {
    if (Name = "Keybind") {
        GuiControl, Choose, Keybind_Key_Main, (RowValue=0 ? 0 : Keybind_Key_Main)
        GuiControl, Choose, Keybind_Key_Win, (RowValue=0 ? 1 : Keybind_Key_Win)
        GuiControl,, Keybind_Key_CapsLock, (RowValue=0 ? 0 : Keybind_Key_CapsLock)
        GuiControl, Choose, Keybind_Key_Shift, (RowValue=0 ? 1 : Keybind_Key_Shift)
        GuiControl, Choose, Keybind_Key_Alt, (RowValue=0 ? 1 : Keybind_Key_Alt)
        GuiControl, Choose, Keybind_Key_Ctrl, (RowValue=0 ? 1 : Keybind_Key_Ctrl)
        GuiControl, Choose, Keybind_Option_Type, (RowValue=0 ? 1 : Keybind_Option_Type)
        GuiControl, Choose, Keybind_Option_Mode, (RowValue=0 ? 1 : Keybind_Option_Mode)
        GuiControl,, Keybind_Option_GoBlue, (RowValue=0 ? 0 : Keybind_Option_GoBlue)
        GuiControl, Choose, Keybind_Option_Remap, (RowValue=0 ? 1 : Keybind_Option_Remap)
        GuiControl, Choose, Keybind_Option_Preset, (RowValue=0 ? 1 : Keybind_Option_Preset)
        GuiControl,, Keybind_Option_Website, (RowValue=0 ? "https://" : Keybind_Option_Website)
    }
}
    ; The two button subs running that function
KeybindMenu_Add:
    SetGui(Keybind, 0) ; Clear all form boxes
    Gui Keybind:Show, Center w400 h300, Add Keybind ; Open the Keybind Edit GUI with a new keybind
    Return
KeybindMenu_Edit:
    SetGui(Keybind, 0) ; Clear all form boxes
    Gui Keybind:Show, Center w400 h300, Edit Keybind ; Open the Keybind Edit GUI with the currently selected row
    Return
    ; The code creating the buttons
Gui Add, Button, -Wrap x55 y40 w120 h30 gKeybindMenu_Add, &Add Keybind
Gui Add, Button, -Wrap Disabled x185 y40 w120 h30 gKeybindMenu_Edit vKeybindMenu_Edit, &Edit Keybind

但是,当我打开菜单,更改某些内容,然后退出并单击两个按钮之一时,什么也没有发生 - 输入字段不会清除/重置。

如何解决这个问题?

编辑:我刚刚意识到我的输入字段的代码可能很重要 -

Gui Add, ComboBox, x230 y24 w140 h200 vKeybind_Key_Main, LButton|RButton|MButton|XButton1|XButton2|WheelDown|WheelUp|WheelLeft|WheelRight|Space|Tab|Enter|Escape|Backspace|Delete|Home|End|PgUp|PgDn|Up|Down|Left|Right|PrintScreen|Numpad0|Numpad1|Numpad2|Numpad3|Numpad4|Numpad5|Numpad6|Numpad7|Numpad8|Numpad9|NumpadDot|NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24
Gui Add, DropDownList, x15 y70 w120 AltSubmit vKeybind_Key_Win, No Win||Left Win|Right Win|Both Win|Either Win
Gui Add, CheckBox, x140 y73 w120 vKeybind_Key_CapsLock, CapsLock
Gui Add, DropDownList, x265 y70 w120 AltSubmit vKeybind_Key_Shift, No Shift||Left Shift|Right Shift|Both Shift|Either Shift
Gui Add, DropDownList, x15 y105 w120 AltSubmit vKeybind_Key_Alt, No Alt||Left Alt|Right Alt|Both Alt|Either Alt
Gui Add, DropDownList, x140 y105 w120 AltSubmit vKeybind_Key_Ctrl, No Ctrl||Left Ctrl|Right Ctrl|Both Ctrl|Either Ctrl

Gui Add, DropDownList, x15 y150 w120 AltSubmit vKeybind_Option_Type gKeybind_Option_Type-Changed, Remap||Preset|Website|App|Custom
Gui Add, DropDownList, x140 y150 w120 AltSubmit vKeybind_Option_Mode gKeybind_Option_Mode-Changed, Either Mode||Orange Mode|Blue Mode
Gui Add, CheckBox, x265 y153 w120 vKeybind_Option_GoBlue, Go to Blue

Gui Add, ComboBox, x15 y195 w180 h200 vKeybind_Option_Remap, Disable Keybind||LButton|RButton|MButton|XButton1|XButton2|WheelDown|WheelUp|WheelLeft|WheelRight|Space|Tab|Enter|Escape|Backspace|Delete|Home|End|PgUp|PgDn|Up|Down|Left|Right|PrintScreen|Numpad0|Numpad1|Numpad2|Numpad3|Numpad4|Numpad5|Numpad6|Numpad7|Numpad8|Numpad9|NumpadDot|NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24
Gui Add, DropDownList, x15 y195 w180 AltSubmit vKeybind_Option_Preset, Restart Program||Toggle Emulated Numpad|Send Notification
Gui Add, Edit, x15 y195 w180 r2 -WantReturn Wrap vKeybind_Option_Website, https://

GuiControl, Hide, Keybind_Option_Remap
GuiControl, Hide, Keybind_Option_Preset
GuiControl, Hide, Keybind_Option_Website
GuiControl, Hide, Keybind_Option_App
GuiControl, Hide, Keybind_Option_Custom
if-statement autohotkey conditional-operator
1个回答
0
投票

通过您发布的代码,可以观察到两件事:

  1. 您正在将一个空白变量传递给函数(其中,从什么 可以理解,应该是字符串)。

  2. 要在GuiControl中使用三元运算符,需要启用 字段中的表达模式(%符号)。

    ;函数与代码 SetGui(名称, RowValue=0) {

    if (Name = "Keybind") {
            GuiControl, Choose, Keybind_Key_Main,% (RowValue=0 ? 0 : Keybind_Key_Main)    ; % sign to expression mode
            GuiControl, Choose, Keybind_Key_Win,% (RowValue=0 ? 1 : Keybind_Key_Win)
            GuiControl,, Keybind_Key_CapsLock,% (RowValue=0 ? 0 : Keybind_Key_CapsLock)
            GuiControl, Choose, Keybind_Key_Shift,% (RowValue=0 ? 1 : Keybind_Key_Shift)
            GuiControl, Choose, Keybind_Key_Alt,% (RowValue=0 ? 1 : Keybind_Key_Alt)
            GuiControl, Choose, Keybind_Key_Ctrl,% (RowValue=0 ? 1 : Keybind_Key_Ctrl)
            GuiControl, Choose, Keybind_Option_Type,% (RowValue=0 ? 1 : Keybind_Option_Type)
            GuiControl, Choose, Keybind_Option_Mode,% (RowValue=0 ? 1 : Keybind_Option_Mode)
            GuiControl,, Keybind_Option_GoBlue,% (RowValue=0 ? 0 : Keybind_Option_GoBlue)
            GuiControl, Choose, Keybind_Option_Remap,% (RowValue=0 ? 1 : Keybind_Option_Remap)
            GuiControl, Choose, Keybind_Option_Preset,% (RowValue=0 ? 1 : Keybind_Option_Preset)
            GuiControl,, Keybind_Option_Website,% (RowValue=0 ? "https://" : Keybind_Option_Website)
        }
    }
    
    ; The two button subs running that function
    KeybindMenu_Add:
            SetGui("Keybind", 0) ; Keybind is suposed to be a String here or you must populate this var with "keybind" string, with make no sense
            Gui Keybind:Show, Center w400 h300, Add Keybind
    Return
    
    KeybindMenu_Edit:
            SetGui("Keybind", 0) ; Keybind is suposed to be a String here or you must populate this var with "keybind" string, with make no sense
            Gui Keybind:Show, Center w400 h300, Edit Keybind
    Return
    
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.