Creating your own shortcuts

Hotkey Monkey comes with a handful of shortcuts (located in HKMK_Examples.ahk ). However, you will quickly want to write your own.

About shortcut files

For maximum flexibility, shortcuts can be organized in different files. For instance, if you work in a company that has different projects, you could have a global file (containing shortcuts to the company's intranet, a quick access to the phone directory...) and a file for each project (to launch specific tools or web pages). Then you would give each developer the global file and the files of the projects he works on.

From a user's point of view, you only need to know a couple of rules about shortcut files. A shortcut file is an AutoHotkey script that:

  • resides in %HKMK_LIB% (if you don't know what I'm referring to, take a look at the install page).
  • follows the naming convention HKMK_Xxx.ahk , where Xxx is a unique suffix.
  • defines its shortcuts in a function with the same name.

So, to start experimenting, you can create a file called %HKMK_DIR%\HKMK_SandBox.ahk :

    ; define your shortcuts here...

Whenever you add or modify a shortcut file, you can reflect the changes in Hotkey Monkey with the reload shortcut.

That being said, we can now start writing shortcuts:

Running programs / web pages

As we've already seen, this is performed with AutoHotkey's Run command:

; Simple URL example
HKMK_addShortcut("hkmk                  Hotkey Monkey home page", "Run,")

; Simple program example
HKMK_addShortcut("note                  Open the notepad", "Run, notepad.exe")

These examples are straightforward.

Just note that the shortcut and its description are in a single character string (AutoHotkey does not have complex data structures like maps). You can use tabs or spaces as delimiters.

Auto-typing text

The Send command can be used to abbreviate commonly used words. For instance, we all regularly write about the city with the longest name in the world:

HKMK_addShortcut("ll                    That city in North Wales", "Send, Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch")

Whenever you need to type it, you can now use "Windows + Down, ll, Enter".

A more likely example is a closing line for your emails:

HKMK_addShortcut("s,                    Writes 'Sincerely yours,'", "Send, Sincerely yours```,")

Note that there is some sort of mini escape hell to make sure the comma is actually sent as a character, and not interpreted as part of the AutoHotkey command. Two characters must be escaped in this way:

  • the comma, escaped as ```,
  • the double-quote, escaped as ""

You can also send control keys (as Enter , BackSpace ) with the SendRaw command. See the AutoHotkey documentation for more information.

An advanced example : using subs and shortcut parameters

Suppose we want to create a shortcut to provide quick access to Wikipedia . We've already seen how to launch a web page:

HKMK_addShortcut("wk                    Wikipedia", "Run,")

However, this is a bit limited. When we go to Wikipedia, what we generally want to do is look for something. This first version of the shortcut simply leads us to the front page; we still need to manually click into the search field, type the search terms and press enter.

There is a much better way to write this shortcut: we can use shortcut parameters to type the search terms directly in Hotkey Monkey.

First of all, let's see how Wikipedia's search URL works; if I search "monkey typewriter", the result page has the following URL:

We're going to tell Hotkey Monkey how to build this URL from the user's input. To begin with, we externalize the shortcut in a Sub . This is required for complex shortcuts that won't fit in a single AutoHotkey instruction:

    HKMK_addShortcut("wk <searchTerms>  Wikipedia", "GoSub, wikipedia")

; The sub for the 'wk' shortcut
; Notice that it is out of HKMK_SandBox()
    ; Your code goes here

Now for the parameters: when you type more than one word in Hotkey Monkey, only the first word is used to select a shortcut, but the whole "sentence" is saved in an indexed variable called promptParams . So if you type "wk monkey typewriter", the following variables are defined by the time the shortcut's code is reached:


This gives us the structure of our wikipedia Sub: if promptParam2 does not exist (no parameters), go directly to the front page; otherwise, build the search URL by appending promptParam2 ...promptParamN . The only thing left is to implement it:

        ; The base URL
        wkUrl =
        if (promptParams2 != "") {
                ; If search terms are specified, build the URL to the search Form
                wkUrl = %wkUrl%/wiki/Special:Search?search=
                ; Add search terms to the URL, separated by '+'
                paramIndex = 2
                Loop {
                        nextTerm := promptParams%paramIndex%

                        ; Stop when there are no more search terms to add
                        if (nextTerm == "") {
                        if (paramIndex > 2) {
                                wkUrl = %wkUrl%+
                        wkUrl = %wkUrl%%nextTerm%
                ; Add the final 'go' parameter
                wkUrl = %wkUrl%&go=Go

        Run, %wkUrl%
Dealing with AutoHotkey's variables can get a bit confusing when you start mixing the "traditional" (=) and "expression" (:=) syntices. I must admit that it takes me some trial-and-error to know when to use or not to use percent signs, when to concatenate using a dot, etc. Don't hesitate to use MsgBox to debug your code.

Our wk shortcut is now parameterized. We can type our search terms directly from the prompt:

Using the SSH shortcuts

One of the reasons for writing Hotkey Monkey was to simplify access to the UNIX servers I use at work. The distribution comes with a convenience function to configure SSH access to a server using the following applications:

  • for shell access: Putty or a Cygwin X terminal (choose the one that best suites your needs).
  • to transfer files: WinSCP .

First you need to install these applications on your machine (refer to their respective websites for details).

Then you use the function like this:

    global winscpPath := "C:\Program Files\WinSCP\WinSCP.exe"
    global startxwinPath := "C:\cygwin\usr\X11R6\bin\startxwin.bat"
    global puttyPath := ""

The three global variables define the paths to the applications. Leave them blank for the ones you don't want to use (like we did for Putty in the example).

The HKMK_addSshShortcuts takes three mandatory parameters:

  • the username,
  • a short name for the server (used for the shortcut names),
  • the full DNS name or IP address of the server.

Additionally, you can specify the password as a fourth parameter. If you do so, Hotkey Monkey will generate a shortcut to type it.

Our example would generate the following shortcuts:

Notes about Cygwin

To be able to run X terminals, you need to install Cygwin/X . It is part of the Cygwin setup, but not enabled by default. To configure it, follow the instructions from the manual .

When this is done, you still need to make a small change to Cygwin/X's startup script. The file to modify is C:\cygwin\usr\X11R6\bin\startxwin.bat . Look for the following:

REM Startup an xterm, using bash as the shell.

%RUN% xterm -e /usr/bin/bash -l

And replace it with:

REM Startup an xterm, using bash as the shell.


IF NOT DEFINED ARG1 %RUN% xterm -fa "Courier" -fs 20 -e /usr/bin/bash -l

IF DEFINED ARG1 %RUN% xterm -title %2 -fa "Courier" -fs 20 -e /usr/bin/bash -l -c "%1 %2 %3 %4 %5 %6 %7 %8 %9"

This will let Hotkey Monkey specify a command to be run when it calls the script. Note that I also modified the font using the -fa and -fs options. This is not required, but in my opinion makes the terminal more readable :-)