Hotkey Monkey comes with a handful of shortcuts (located in HKMK_Examples.ahk ). However, you will quickly want to write your own.
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:
So, to start experimenting, you can create a file called %HKMK_DIR%\HKMK_SandBox.ahk :
HKMK_SandBox() { ; 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:
As we've already seen, this is performed with AutoHotkey's Run command:
; Simple URL example HKMK_addShortcut("hkmk Hotkey Monkey home page", "Run, http://hkmk.sourceforge.net/") ; 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.
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:
You can also send control keys (as Enter , BackSpace ) with the SendRaw command. See the AutoHotkey documentation for more information.
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, http://en.wikipedia.org")
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:
http://en.wikipedia.org/wiki/Special:Search?search=monkey+typewriter&go=Go
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_SandBox() { HKMK_addShortcut("wk <searchTerms> Wikipedia", "GoSub, wikipedia") } ; The sub for the 'wk' shortcut ; Notice that it is out of HKMK_SandBox() wikipedia: ; Your code goes here return
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:
promptParams1=wk promptParams2=monkey promptParams3=typewriter
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:
wikipedia: ; The base URL wkUrl = http://en.wikipedia.org 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 == "") { break } if (paramIndex > 2) { wkUrl = %wkUrl%+ } wkUrl = %wkUrl%%nextTerm% paramIndex++ } ; Add the final 'go' parameter wkUrl = %wkUrl%&go=Go } Run, %wkUrl% return
Our wk shortcut is now parameterized. We can type our search terms directly from the prompt:
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:
First you need to install these applications on your machine (refer to their respective websites for details).
Then you use the function like this:
HKMK_SandBox() { global winscpPath := "C:\Program Files\WinSCP\WinSCP.exe" global startxwinPath := "C:\cygwin\usr\X11R6\bin\startxwin.bat" global puttyPath := "" HKMK_addSshShortcuts("someUser","someHost","somehost.mycompany.com","somePass") }
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:
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:
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. SET ARG1=%1 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 :-)