AutoHotkey

Getting started with AutoHotkey

Remarks#

AutoHotkey is a free, open-source custom scripting language for Microsoft Windows, initially aimed at providing easy keyboard shortcuts or hotkeys, fast macro-creation and software automation that allows users of most levels of computer skill to automate repetitive tasks in any Windows application. User interfaces can easily be extended or modified by AutoHotkey (for example, overriding the default Windows control key commands with their Emacs equivalents). The Autohotkey installation includes its own extensive help file with an always updated web based version.

You can write mouse or keyboard macros, remap keys, create hotkeys, expand abbreviations, change clipboard contents, and make executables to run hotkey scripts on computers without AutoHotkey installed.

Versions#

AutoHotkey 1.0.* - also retroactively known as AutoHotkey Basic, Classic, Vanilla, etc.

(Development was discontinued in 2011; Latest stable: 2009)

VersionRelease Date
v1.0.48.052009-09-26
v1.0.97.022011-04-14

AutoHotkey 1.1.* - previously known as AutoHotkey_L.

(Stable and receives updates regularly)

VersionRelease Date
v1.1.24.002016-05-22
v1.1.24.012016-08-02

AutoHotkey 2.0-a*

(Still in alpha stage)

VersionRelease Date
v2.0-a0692015-10-24
v2.0-a0702015-11-09
v2.0-a0712015-12-25
v2.0-a0722015-12-25
v2.0-a0732016-02-05
v2.0-a0742016-03-11
v2.0-a0752016-06-03

Installation or Setup

From Autohotkey Site Documentation

  1. Go to the AutoHotkey Homepage.
  2. Click Download, once downloaded run the executable.
  3. During installation of AutoHotkey, you will be asked to choose from UNICODE or ANSI. In short, you would probably want to choose UNICODE. It has support for non-English letters and numbers (characters).
  4. Keep going until you see an Install button.
  5. Once done, great!

Use as portable software

  1. Go to the AutoHotkey’s download page.
  2. Find the Portable section, choose from UNICODE 32, 64 or ANSI and downloaded.
  3. When choosing the destination folder, pick any correct storedevice external or not.
  4. Now you can opt to associate .ahk files with Autohotkey.exe
  5. Create a plain text file and give it the .ahk extension
  6. Then Right-click on the .ahk file in explorer and click Properties.
  7. In the file Properties, click the Change button next to the “Opens with” option.
    • After clicking Change, you’ll be given a list of programs to open
    the file, select the program you want to use and then click OK or Apply.
    • If the program you want to select is not listed, click the
    Browse button and find the Autohotkey executable (.exe) file and click OK to select that program.
  8. Now .ahk files will run as if autohotkey was installed, great!

If you have chocolatey installed, run the following command as an admin user

choco install autohotkey

Alternatively, it can be built from the source code. See here for details:
https://github.com/Lexikos/AutoHotkey_L/

Hello World

Show a “Hello World!” in message box.

MsgBox, Hello World!

Show a “Hello World!” in tooltip.

#Persistent
Tooltip, Hello World!

Show a “Hello World!” message in the traybar edit.

#Persistent
TrayTip,, Hello World!

Prints “Hello, World” to Standard Output (stdout).

FileAppend, % "Hello, World", *

Show “Hello World” in a GUI

Gui, Add, Text,, Hello World!
Gui, Show, w200 h200
return

GuiClose:
ExitApp

Achieve an effect similar to SplashTextOn

Gui, +AlwaysOnTop +Disabled -SysMenu +Owner  ; +Owner avoids a taskbar button.
Gui, Add, Text,, Some text to display.
Gui, Show, NoActivate, Title of Window  ; NoActivate avoids deactivating the currently active window.

How to create a Script

Once you have AutoHotkey installed, you will probably want it to do stuff. AutoHotkey is not magic, we all wish it was, but it is not. So we will need to tell it what to do. This process is called “Scripting”.

  1. Right-Click on your desktop.
  2. Find “New” in the menu.
  3. Click “AutoHotkey Script” inside the “New” menu.
  4. Give the script a new name. Note: It must end with a .ahk extension. Ex. MyScript.ahk
  5. Find the newly created file on your desktop and Right-Click it.
  6. Click “Edit Script”.
  7. A window should have popped up, probably Notepad. If so, SUCCESS!

So now that you have created a script, we need to add stuff into the file. For a list of all built-in commands, function and variables, see section 5. Here is a very basic script containing a Hotkey which types text using the Send command when the hotkey is pressed.

^j::
   Send, My First Script
Return

We will get more in-depth later on. Until then, here’s an explanation of the above code.

  • The first line. ^j:: is the Hotkey. ^ means CTRL, j is the letter j. Anything to the left of :: are the keys you need to press.
  • The second line. Send, My First Script is how you SEND keystrokes. SEND is the command, anything after the comma (,) will be typed.
  • The third line. Return. Return will become your best friend. It literally STOPS code from going any further, to the lines below. This will prevent many issues when you start having a lot of stuff in your scripts.
  1. Save the File.
  2. Double-Click the file/icon in the desktop to run it. Open notepad or (anything you can type in) and press Ctrl and J.
  3. Hip Hip Hooray! Your first script is done. Go get some reward snacks then return to reading the rest of this tutorial.

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow