What is AutoHotkey?


ahk_logo__two_rows.svg

AutoHotkey (abbreviated: “AHK” or “ahk”) is a free, open-source programming language which wraps low-level procedures and functionality of the Windows Operating System into high-level, simplified commands. I am not affiliated with AutoHotkey’s development, but I’ve been using and enjoying it for over a decade.


AutoHotkey Overview

Hotkeys

The syntax of AutoHotkey is simple enough that users with no programming background can remap key combinations (called hotkeys) to launch their favorite applications.

An AutoHotkey script containing the following 3 lines will launch Window’s Notepad.exe whenever the user presses the hotkey Windows+F1 :

#F1::
       Run, notepad.exe
return

Starting out, beginners can also assign hotkeys to trigger a few cherry-picked AutoHotkey commands.

Hotstrings

In addition to triggering code via hotkeys, AutoHotkey also has a feature called hotstrings. With hotstring mapping, you can define a simple shorthand phrase that you want to automatically expand whenever you type it. For example, you can configure an AutoHotkey script to insert the text “for what it’s worth” whenever you type the hotstring “fwiw” and press Enter with the following line of code:

::fwiw::for what it's worth

And More!

AutoHotkey is great for short scripts to suit simple needs.

But AutoHotkey is also robust enough to develop complex applications such as:

Whether you’re an advanced power user with a million apps you want to bind to each function key, a graphic interface designer who wants to prototype some basic windows quickly, or if you just want to open your music player faster, AutoHotkey has something to offer you.

In a Nutshell

AutoHotkey is a framework that can help you expedite your common workflows, whatever they might be.


AutoHotkey Resources

The Official Documentation:

And the official documentation for AutoHotkey is excellent. The entire manual is extensive but cleanly laid out, and can even be read offline using the .chm file installed with AutoHotkey. By default this help file will be installed to this location on your hard drive: C:\Program Files\AutoHotkey\AutoHotkey.chm (for 64-bit installations).

The Community Forums:

AutoHotkey has been around since 2003. As you explore and experiment with the AutoHotkey language you can typically find many elegant solutions, example scripts, and forum discussions for almost every problem you face.

The community surrounding AutoHotkey is still active, and you can find a wide variety of scripts and tutorials on the online AutoHotkey forums ranging from simple recipes for moving and listing windows, to technical help with a variety of common (and uncommon) syntax pitfalls. There are even a few users who have posted comprehensive guides over the years describing how to use AutoHotkey’s arrays, objects, classes in great and exhaustive detail.

As you experiment, never be afraid to go to your favorite search engine and type in my topic, ahk. I’ve been surprised by how many high-quality AutoHotkey forum posts I’ve consistently found over the years by adding ahk to an otherwise generic search query.

Links to Help You Get Started:

AutoHotkey is a simple and powerful language. If you’ve never programmed before, it can be a fun place to begin. I highly recommend starting with the official AutoHotkey Beginner Tutorial (it has a lot of simple examples you can try as soon as you install AutoHotkey)!

Download and learn more at the official AutoHotkey website:

AutoHotkey Home
  (download here):
https://www.autohotkey.com/
AutoHotkey Manual: https://www.autohotkey.com/docs/AutoHotkey.htm
AutoHotkey Forum: https://www.autohotkey.com/boards/
AutoHotkey Beginner
  Tutorial:
https://www.autohotkey.com/docs/Tutorial.htm

Read AutoHotkey’s source code:

AutoHotkey Source Code: https://github.com/Lexikos/AutoHotkey_L/

Read a bit about its history here:

Wikipedia: https://en.wikipedia.org/wiki/AutoHotkey#History
History: https://www.autohotkey.com/foundation/history.html
The transition
to AutoHotkey_L
https://autohotkey.com/board/topic/58864-my-status-and-website-changes/

Tip

Interested in programming with AutoHotkey? Need a development tool?

If you install AutoHotkey, you can start coding right away using notepad.exe which is available on every edition of Windows. But if you want something more robust and comfortable….

For Beginners and Enthusiasts:

Look no further than Notepad++!

If you want to set up syntax-highlighting, the recipe I used can be found here:


For Advanced Users:

Look no further than SciTE4AutoHotkey!

SciTE4AHK is an excellent IDE[1] for AutoHotkey. It features built-in code completion[2] for AHK commands, code completion for variables in the currently opened .ahk file, syntax-highlighting, a debugger with breakpoints, and variable inspection at runtime (including hierarchies of nested objects or arrays).

You can read discussions about its development and history here:



First Steps

One of the greatest things about AutoHotkey is you can type some code in a text editor like Notepad.exe or Notepad++, give the text file the .ahk extension, and it automatically becomes an executable script.

Hint

If you’re interested in trying out AutoHotkey, the official documentation has an excellent Beginner Tutorial here: https://www.autohotkey.com/docs/Tutorial.htm. (For future reference, this tutorial is listed as Tutorial (quick start) in the AutoHotkey documentation’s table of contents.)

Once you’ve installed AutoHotkey with the official installer, you can write AutoHotkey scripts in any text editor.

  • After typing some code, save it with the extension .ahk and your executable script file will be ready.
  • Alternatively, you can save your code as a .txt file then rename that text file in Windows Explorer to have the .ahk extension instead (for example: rename my_script.txt to my_script.ahk). And voila, as soon as your file has the .ahk extension, your script is ready to run!

Double-click this file to run your code!

Note

You can exit an AutoHotkey script at any time by right-clicking green “H” icon in the Notification Area, then selecting “Exit”. If you have more than one AutoHotkey script running, hover over each icon until you see a tooltip pop up. The tooltip will display the filename of the running script.


Baking Your AutoHotkey Scripts

You might be saying, “That’s nice and all, but what if I want to make an official executable with AutoHotkey to impress my friends?” (Or you might be thinking “But what about portability, do I need to make a .zip every time I want to distribute my code?”)

The AutoHotkey installer can optionally add a compiler[3] to your Windows Explorer context menu, giving you the ability to bake .ahk scripts into a single .exe executable file. These AutoHotkey script.exe files can either be run locally, or shared and run on Windows PCs which do not have AutoHotkey installed.

Note

Compiling your .ahk scripts into an .exe file can even be useful if your PC already has AutoHotkey installed. For example, if your program spans multiple files then you can to bake them all into a single executable for portability or cleanliness.




Glossary

[1]

IDE: Acronym for Integrated Development Environment.

Refers to an application which facilitates programming. Typically IDEs include tools to assist in productively writing, running, and debugging code.

See: https://wikipedia.org/wiki/Integrated_development_environment.

[2]

Code Completion: Typically a dropdown list suggesting words or commands based on context. Present in many IDEs (and even in some text editors, see Notepad++). Expedites programming by having the software remember and suggest specific variables, functions, and syntax conventions.

For example, if you can only remember part of a function named “Cat_Says_Meow()”, you can type the beginning “Cat_Says_”, and code completion would present you with a dropdown item containing “Cat_Says_Meow()”. Compared to using a simple text editor, this feature allows you to remain focused on the present task (instead of sifting and searching for a half-remembered phrase, copying or re-memorizing it, scrolling back to where you began, then reorienting to your original context).

See: https://en.wikipedia.org/wiki/Intelligent_code_completion.

[3]

Compiler: A compiler is a program which takes souce code and translates it into another programming language. Typically when you hear the phrase “this code was compiled”, it means that a human-readable text file was turned into an execuable program which can now be launched by a user.

See: https://en.wikipedia.org/wiki/Compiler.