Many users have asked for a straightforward approach to remapping hotkeys. Since AutoHotkey is a powerful yet accessible tool, I have put together this guide to help you get started. While you can use this utility for complex automation, we will focus on the fundamentals of key remapping and basic macro creation. I recommend reading through this entire guide before writing your first line of code to ensure you understand the syntax and logic.
AutoHotkey is a free, open-source utility for Windows. Through my own experience using it for gaming and productivity, I have found it to be the most reliable way to handle input automation. It allows you to:
- Automate almost anything by sending keystrokes and mouse clicks. You can write a mouse or keyboard macro by hand or use the macro recorder.
- Create hotkeys for keyboard, joystick, and mouse. Virtually any key, button, or combination can become a hotkey.
- Expand abbreviations as you type them. For example, typing "btw" can automatically produce "by the way".
- Create custom data-entry forms, user interfaces, and menu bars.
- Remap keys and buttons on your keyboard, joystick, and mouse.
- Respond to signals from hand-held remote controls via the WinLIRC client script.
- Convert any script into an EXE file that can be run on computers that don't have AutoHotkey installed.
Before proceeding, download and install the software using the links below:
AutoHotkey 1.0.48.05 installerAutoHotkey 1.0.48.05 zip
Now, let's create your first script:
- Right-click on your desktop (or your preferred directory) and select "New" > "AutoHotkey script".
- An icon will appear; give it a descriptive name, such as "test".
- Right-click the script icon and choose "Edit script". A Notepad window will open. You can clear the default text or leave it; it will not affect your custom code.
When you save this file, ensure it retains the ".ahk" extension. This extension identifies the file as an AutoHotkey script. To run it, double-click the file. A tray icon will appear in the lower right corner of your taskbar. To stop the script, right-click that tray icon and select "Exit".
Let's begin programming. Open your script and add this line:
^space::Run www.dota-allstars.com
Save and run the script. When you press Ctrl + Space, your default browser will open the specified URL. In this syntax, the caret (^) represents the Ctrl modifier, :: defines the hotkey trigger, and the command following it is the action performed.
Next, try these two methods for remapping:
q::Send {enter}hello world!!1{sleep 700}{backspace}
w::space
The first line uses the Send command, which requires curly braces {} for special keys. The second line is a direct remap, which is simpler and does not require braces. Test these in a text editor to observe the behavior.
For multi-line macros, use a return to end the sequence:
q::
Send {enter}hello world!!1
sleep 700
Send {backspace}
sleep 1500
Msgbox Hello
Return
You can also trigger actions based on key states (press vs. release):
enter::tooltip DOWN
enter up::tooltip UP
space::SoundBeep
space up::Msgbox BEEEEEP!
When writing scripts, comments are essential for maintenance. Note that some editors may strip leading spaces, so ensure you include a space before the semicolon (;) to ensure the interpreter recognizes it as a comment:
#persistent ;This prevents the script from shutting down immediately
msgbox This is a message box, it will show
sleep 1000
msgbox This is a message box too ;<- Add a space.. This won't show. It's a comment!
sleep 1000
/*
Multi-line comments can be wrapped in slash-asterisk blocks.
*/
In my personal setup, I use specialized mouse buttons (Logitech MX518) for macros:
*XButton1::Send, {F1}^8{Numpad7}
*XButton1 up::Send {click}8
*XButton2::Send, {F1}^8{Numpad8}
*XButton2 up::Send {click}8
For game-specific automation, use the #ifWinActive directive to prevent hotkeys from firing globally. I recommend using the wildcard (*) prefix to ensure the hotkey fires even if modifier keys like Alt or Shift are held down:
#ifWinActive, Warcraft III
;;Mouse Wheel to Item Slots
*MButton::Send {F1}{Numpad8}{LButton}8
*WheelUp::Send {F1}{Numpad7}{LButton}8
*WheelDown::Send {F1}{Numpad4}{LButton}8
You can also toggle functionality using the Hotkey command. The $ prefix prevents the script from triggering itself via artificial input:
$y::Send, {Numpad7}
*Enter::
Hotkey, $y, Toggle
return
Finally, for complex combos, use sleep to time your actions precisely. For example, in a game, you might queue a blink ability after a channel:
!c::
send c
sleep 1000
send {numpad2}+{click}
return
This script uses Shift+Click to queue the move command, ensuring efficiency. You may need to adjust the sleep duration based on your specific latency or game mechanics.
Follow these links to download the software:
AutoHotkey 1.0.48.05 installerAutoHotkey 1.0.48.05 zip