As a scripting language, AutoHotkey was designed to be used as an automation and keymapping tool for Microsoft Windows.
In this guide, I will show you how to make your own shortcuts by changing the functions of your keyboard. But do understand: this is just an introduction for novices and the curious non-programmers. Anyone can code, but everyone should at least start somewhere.
Good thing that AutoHotkey is (almost) as simple as counting 1, 2, 3!
Okay, so before starting your scripting journey with AutoHotkey, you will first need to download and install the script language’s compiler. You can get it at their website for free.
Just check if you really are on the right website.
After that, you should run the installer, click on some stuff, and let it do the work. The installation process shouldn’t take long.
Once that is done, you will need to choose where to write your scripts.
Using Text Editors
Simple commands in AutoHotkey, like remapping keys, have no need for advanced IDEs.
In fact, even the humble Notepad can work well 98% of the time. The only problem here would be if you mistyped a code and had no idea where you went wrong. Now that would be a headache.
But if you are a beginner, do not fret. You can use other programs; Notepad++ and AHK Studio Master are good alternatives despite not being full-fledged IDEs.
Right: Notepad; Left: Notepad++; Back: AHK Studio Master
In a way, you can say that Notepad++ is kinda similar to the original Notepad. That is partly true. However, it’s a lot easier to see if you mistyped a parenthesis at Notepad++. It also has a ton of features that you will definitely not use in this guide.
Meanwhile, AHK Studio Master one ups Notepad++ by being a dedicated text editor for AutoHotkey.
For the rest of this tutorial, I will be using Notepad++. But feel free to use Notepad or AHK Studio Master if that is your cup of tea.
If you are using Notepad++, you may need to input these four lines of code at the top.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
You may want to ignore these for now. But if it helps you understand, these lines make sure that your code will run no matter where you save and run your script. The semicolon ( ; ) in these means that they are referring to a comment. Read the corresponding comment to understand their functions.
Now, in order to remap a key, you will need to type in a code. Suppose we hate the “p” key so much that we want it to spit out “q” whenever we press that button. We put in a code like this:
p:: send q
You can read that code as the “p” key has the function of sending a “q”. Or, the “p” key spits out a “q”.
Either way works just as well.
I made a comment. Can you see it?
In order to test your code, you must first save it into an “.ahk” file then run it like you would normally do an “.exe” file. Try typing “p” on a text bar or spare Notepad and watch it turn into a “q” instead.
Of course, this can’t last forever. Once you’ve shut down your pc, the script will automatically terminate. It won’t be active when you open it again.
Wait. What’s that, you say?
You need it to turn off right now?
Okay, fine. If you look at your taskbar, you will find a logo that has a green box with a white, capitalized H.
Right-clicking it will show a menu with an “Exit” button. That will solve your problems.
Now, AHK will also let you do a combination of keys to spit out a letter or a group of letters. In fact, you can also make it type your name for you in the blink of an eye!
Adding in an “&” will allow you to use two keys in order to form a command. In this case, pressing “ctrl” and “p” will bring out “q”.
Now, imagine playing your favorite FPS game with AHK running a code like this:
Try experimenting to see what happens when you remove the “return” code
Of course, there is more to doing AutoHotkey than what can fit in a single article. As an automation tool, it can also automatically input commands such as repetitive mouse clicks, automatic form filling, and many more. In fact, the AHK Studio Master was even built out of AutoHotkey. How cool is that?