3

I have few short hotstrings/hotkeys. If I type "one", there's a corresponding actions, if I typed two, there another corresponding actions.

My question is, how can I make a single hotkey for all, that when I press a key, a drop-down list/msgbox will appear, then I can choose an item, and upon clicking it, it will perform the corresponding macro based on the list below?

::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

Also, is Autohotkey a good one for learning scripts? Or AutoIT? Or I should learn major scripting language (like the ones I usually heard - Perl, PhP, etc.)

We're those programming language able to do simple steps, like recording just keyboard pressing and mouse movements?

. Thanks,

Faye

2

AHK-example:

; create the gui:
Gui, +AlwaysOnTop
; DropDownList:
; Gui, Add, DDL, gAction vChoise Choose1 w200, one|two|three|four
; ListBox:
Gui, Add, ListBox, gAction vChoise 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 (Choise = "one")
    MsgBox, 1st action 
If (Choise = "two")
    MsgBox, 2nd action
If (Choise = "three")
    MsgBox, 3rd action
If (Choise = "four")
    MsgBox, 4th action
return

GuiClose:
ExitApp

EDIT

If you want to choose an action by using the Up/Down Arrows and Enter, you need to add a default Button to the gui

or this:

Gui, +AlwaysOnTop
Gui, Add, ListBox, gAction vChoise 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 (Choise = "one")
        MsgBox, 1st action 
    If (Choise = "two")
        MsgBox, 2nd action
    If (Choise = "three")
        MsgBox, 3rd action
    If (Choise = "four")
        MsgBox, 4th action
}
return

#If WinActive("Actions ahk_class AutoHotkeyGUI")

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

#If

GuiClose:
ExitApp
5
  • Hello @user3419297, thank you, this is very helpful for us. One more thing, can you please edit this a little bit 1.] Make the box bigger with all the options 1, 2, 3, 4 already showing (without the need to click the drop-down arrow to reveal the options), buttons maybe.. 2.] Make the autohotkey icon stay on the system tray.. Thanks. – Faye Oct 30 '17 at 5:50
  • Hi @user3419297: Already using your 'answer' for our Invoice Recording Macro - DONE.. Thanks. – Faye Oct 30 '17 at 7:47
  • Hi @user3419297: How can we make it to choose with using the Up/Down Arrows then pressing Enter (instead of the mouse)? – Faye Oct 30 '17 at 9:13
  • Thanks, working fine now. :) By the way, are these codes required or mandatory in every new script, because it's always there everytime I create ahk in notepad?: #NoEnv #Warn SendMode Input SetWorkingDir %A_ScriptDir% ? – Faye Oct 30 '17 at 23:38
  • They are NOT required in EVERY script. They are just directives or commands recommended for better performance, compatibility, speed and reliability. You can remove or add more of them by editing the template file in the %WINDIR%\ShellNew folder. Check the individual description for each of them in the documentation. – user3419297 Oct 31 '17 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.