AutoHotkey doesn't do anything on its own; it needs a script to tell it what to do. A script is simply a plain text file with the
.ahk filename extension containing instructions for the program, like a configuration file, but much more powerful. A script can do as little as performing a single action and then exiting, but most scripts define a number of hotkeys, with each hotkey followed by one or more actions to take when the hotkey is pressed.
#z::Run https://www.autohotkey.com ; Win+Z ^!n:: ; Ctrl+Alt+N if WinExist("Untitled - Notepad") WinActivate else Run Notepad return
Tip: If your browser supports it, you can download any code block (such as the one above) as a script file by clicking the button which appears in the top-right of the code block when you hover your mouse over it.
There are a couple of common ways to create a script file:
.ahkfilename extension. On some systems you may need to enclose the name in quotes to ensure the editor does not add another extension (such as .txt).
Be sure to save the file as UTF-8 with BOM if it will contain non-ASCII characters. For details, see the FAQ.
.ahkextension if it is visible).
See Scripting Language for details about how to write a script.
To open a script for editing, right-click on the script file and select Edit Script. If the script is already running, you can use the Edit command or right-click the script's tray icon and select Edit This Script. By default this will open Notepad, but that can be changed by writing to the registry as shown here. Of course, you can always open your text editor first and then open the script as you would any other text file.
After editing a script, you must run or reload the script for the changes to take effect. A running script can usually be reloaded via its tray menu.
With AutoHotkey installed, there are several ways to run a script:
Most scripts have an effect only while they are running. Use the tray menu or the ExitApp command to exit a script. Scripts are also forced to exit when Windows shuts down. To configure a script to start automatically after the user logs in, the easiest way is to place a shortcut to the script file in the Startup folder.
Scripts can also be compiled; that is, combined together with an AutoHotkey binary file to form a self-contained executable (.exe) file.
By default, each script adds its own icon to the taskbar notification area (commonly known as the tray).
The tray icon usually looks like this (but the color or letter changes when the script is paused or suspended):
Right-click the tray icon to show the tray menu, which has the following options by default:
By default, double-clicking the tray icon shows the script's main window.
The Menu command can be used to customise the tray icon and menu.
The #NoTrayIcon directive can be used to hide the tray icon.
The script's main window is usually hidden, but can be shown via the tray icon or one of the commands listed below to gain access to information useful for debugging the script. Items under the View menu control what the main window displays:
Known issue: Keyboard shortcuts for menu items do not work while the script is displaying a MsgBox or other dialog.
The built-in variable A_ScriptHwnd contains the unique ID (HWND) of the script's main window.
The title of this window is used by the #SingleInstance and Reload mechanisms to identify other instances of the same script. Changing the title prevents the script from being identified as such. The default title is equivalent to the expression
A_ScriptFullPath (A_IsCompiled ? "" : " - AutoHotkey v" A_AhkVersion).
Closing this window with WinClose (even from another script) causes the script to exit, but most other methods just hide the window and leave the script running.
See Passing Command Line Parameters to a Script for command line usage, including a list of command line switches which affect the program's behavior.
The file AutoHotkey.exe is all that is needed to launch any .ahk script.
[AHK_L 51+]: Renaming AutoHotkey.exe also changes which script it runs by default, which can be an alternative to compiling a script for use on a computer without AutoHotkey installed. For instance, MyScript.exe automatically runs MyScript.ahk if a filename is not supplied, but is also capable of running other scripts.
To silently install AutoHotkey into the default directory (which is the same directory displayed by non-silent mode), pass the parameter /S to the installer. For example:
A directory other than the default may be specified via the /D parameter (in the absence of /S, this changes the default directory displayed by the installer). For example:
AutoHotkey110800_Install.exe /S /D=C:\Program Files\AutoHotkey
Version: If AutoHotkey was previously installed, the installer automatically detects which version of AutoHotkey.exe to set as the default. Otherwise, the default is Unicode 32-bit or Unicode 64-bit depending on whether the OS is 64-bit. To override which version of AutoHotkey.exe is set as the default, pass one of the following switches:
/ANSI: ANSI 32-bit.
/x64: Unicode 64-bit (only valid on 64-bit systems).
/U32: Unicode 32-bit.
For example, the following installs silently and sets ANSI 32-bit as the default:
AutoHotkey110800_Install.exe /S /A32
Uninstall: To silently uninstall AutoHotkey, pass the
/Uninstall parameter to Installer.ahk. For example:
"C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Program Files\AutoHotkey\Installer.ahk" /Uninstall
For AutoHotkey versions older than 1.1.08.00, use
uninst.exe /S. For example:
"C:\Program Files\AutoHotkey\uninst.exe" /S
Note: Installer.ahk must be run as admin to work correctly.
Extract: Later versions of the installer include a link in the bottom-right corner to extract setup files without installing. If this function is present, the
/E switch can be used to invoke it from the command line. For example:
AutoHotkey110903_Install.exe /D=F:\AutoHotkey /E
Restart scripts [v1.1.19.02+]: In silent install/uninstall mode, running scripts are closed automatically, where necessary. Pass the
/R switch to automatically reload these scripts using whichever EXE they were running on, without command line args. Setup will attempt to launch the scripts via Explorer, so they do not run as administrator if UAC is enabled.
Taskbar buttons [v1.1.08+]: On Windows 7 and later, taskbar buttons for multiple scripts are automatically grouped together or combined into one button by default. The Separate taskbar buttons option disables this by registering each AutoHotkey executable as a host app (IsHostApp).
[v1.1.24.02+]: For command-line installations, specify
/IsHostApp=1 to enable the option and
/IsHostApp=0 to disable it.
The installer GUI has an option "Add 'Run with UI Access' to context menus". This context menu option provides a workaround for common UAC-related issues by allowing the script to automate administrative programs - without the script running as admin. To achieve this, the installer does the following:
If any these UIA files are present before installation, the installer will automatically update them even if the UI Access option is not enabled.
For command-line installations, specify
/uiAccess=1 to enable the option and
/uiAccess=0 to disable it. By default, the installer will enable the option if UAC is enabled and the UI Access context menu option was present before installation.
Scripts which need to run other scripts with UI access can simply Run the appropriate UIA.exe file with the normal command line parameters.
ComObjActive("Word.Application")will fail because Word is not marked for UI Access.
#InstallMouseHook) may prevent all mouse hotkeys from working when the mouse is pointing at a window owned by a UIA script, even hotkeys implemented by the UIA script itself. A workaround is to ensure UIA scripts are loaded last.
For more details, see Enable interaction with administrative programs on the archive forum.