Skip to Content

A Modular Hotkey System

For my StrangeLoop workshop I had to do a lot of powerpoint work. To streamline this, I made over 20 AutoHotKey shortcuts to run various ribbon commands. To avoid polluting my keyboard I built them all into a general-purpose system. All shortcuts started by clicking the thumb mouse button and then quickly pressing 1-2 keys in sequence.

#IfWinActive ahk_exe POWERPNT.EXE

pp_func() ; making this a function allows for local variable scopes
{
    pp_cmd := {a2: {cmd: "{alt}adu.2", info: "Set animation time to .2 seconds"}
    , af: {cmd: "{alt}as{home}{down}{right}{enter}", info: "Insert fadein animation"} ; etc etc etc
    , gc: {cmd: "^g{alt}hgac{alt}hgam^+g", info: "center as a group"}} ;closer can't be on newline

pp_input := "?"
pp_info := ""
for pkey, pval in pp_cmd {
    pp_input .=  "," . pkey
    pp_info .= pkey . "       " . pval["info"] . "`n"
}

Input, PowerPointCommand, L2 T1,, %pp_input%
    if (ErrorLevel == "Match") {
        if (PowerPointCommand == "?") {
            MsgBox,,, %pp_info%
        }
        else {
            p_cmd := pp_cmd[PowerPointCommand]["cmd"]
            Send, %p_cmd%
        }
    }
return
}

; Mouse thumb button, you can change this to something else
XButton1::pp_func()
#IfWinActive

Pressing ? will show all of the commands along with descriptions.

How it Works

The trick here is the Input, which accepts a sequence of presses and stores it into a variable. We dynamically construct the matching Input list beforehand— pressing any matching sequence sets the ErrorLevel to “Match”, which is how we know we’ve got something useful. Then we extract the keypresses associated with the command and send them to PowerPoint, which triggers the appropriate ribbon command. That works because {alt}x is equivalent to alt+x. Keypresses after that are not modified.

The L2 T1 param to Input says to accept at most two keystrokes and to timeout after 1 second.

Notes

  • I wrote {alt}abc for clarity; you can also write it !abc. See here for more information on the special characters.
  • AutoHotKey dictionaries are case-insensitive, so adding the key aB will clobber the earlier key Ab. I have a very convoluted workaround for my file launchers, you should probaby just Not Do That.
  • We need to pull out the command from the array before we can Send it because you can’t do interpolated array lookups in a command.
  • The closing brace needs to be on the same line as a command. AHK handles newlines weird.
  • I could have done proper formatting for the pp_info key but got lazy.