Autohotkey,如何创建下拉列表来选择项目

Autohotkey,如何创建下拉列表来选择项目

我有几个短的热字符串/热键。如果我输入“one”,就会有一个对应的操作,如果我输入 two,就会有另一个对应的操作。

我的问题是,如何为所有功能创建一个热键,当我按下一个键时,会出现一个下拉列表/消息框,然后我可以选择一个项目,单击它后,它将根据下面的列表执行相应的宏?

::one::

{

    do this

    do that

}

return

::two::

{

    do this

    do that

}

return

::three::

{

    do this

    do that

}

return

::four::

{

    do this

    do that

}

return

::five::

{

    do this

    do that

}

return

另外,Autohotkey 是学习脚本的好工具吗?还是 AutoIT?或者我应该学习主要的脚本语言(比如我经常听到的那些 - Perl、PhP 等)

我们的编程语言能够执行简单的步骤,例如仅记录键盘按下和鼠标移动?

。 谢谢,

费伊

答案1

AHK 示例:

; create the gui:
Gui, +AlwaysOnTop
; DropDownList:
; Gui, Add, DDL, gAction vChoice Choose1 w200, one|two|three|four
; ListBox:
Gui, Add, ListBox, gAction vChoice w200 h60, one|two|three|four
return

; Press F1 to show the gui:
F1::
CoordMode, Mouse, Screen
MouseMove, 40, 50, 0
Gui, Show, x0 y0, Actions
return


Action:
Gui, Submit ; or
; Gui, Submit, NoHide   ; if you don't want to hide the gui-window after an action
If (Choice = "one")
    MsgBox, 1st action 
If (Choice = "two")
    MsgBox, 2nd action
If (Choice = "three")
    MsgBox, 3rd action
If (Choice = "four")
    MsgBox, 4th action
return

GuiClose:
ExitApp

编辑

如果您想使用向上/向下箭头和 Enter 键选择操作,则需要添加默认按钮到 GUI

或这个:

Gui, +AlwaysOnTop
Gui, Add, ListBox, gAction vChoice w200 h60, one|two|three|four
return

; Press F1 to show the gui:
F1:: Gui, Show, x0 y0, Actions

Action:
If ((A_GuiEvent = "DoubleClick") || (Trigger_Action))
{
    Gui, Submit
    If (Choice = "one")
        MsgBox, 1st action 
    If (Choice = "two")
        MsgBox, 2nd action
    If (Choice = "three")
        MsgBox, 3rd action
    If (Choice = "four")
        MsgBox, 4th action
}
return

#If WinActive("Actions ahk_class AutoHotkeyGUI")

    Enter::
        Trigger_Action := true
        GoSub, Action
        Trigger_Action := false
    return
    
#If

GuiClose:
ExitApp

相关内容