AutoHotKey

From Dual-Boxing.com

Jump to: navigation, search

Contents

AutoHotKey is a powerful scripting utility that allows you to manipulate keyboard and mouse input extensively. AutoHotkey is an open source macro-making utility for Windows that can automate almost anything by sending keystrokes and mouse clicks. It can also create hotkeys for keyboard, mouse, joystick, and handheld remote controls. Similarly, it can create abbreviations that expand as you type them (AutoText). Finally, it makes it easy to create your own graphical user interfaces and custom menus. [1]

This discussion will focus on how we can manipulate the AutoHotKey scripts to enable us to multi-box effectively with the focus on key broadcasting.

Legal Issues

Please be aware that the use of AutoHotKey may be illegal in some online games. Check the Terms of Service of your game or speak to their Customer Service department.

World of Warcraft

Currently Blizzard allows the use of 3rd party key-broadcasting software, see GM Conversations, however, automation is against the Terms of Use. Automation can be defined as any action taken by your character in-game that is not the direct result of a user action.

For AutoHotKey this means that any kind of delay introduced in your script between sending commands is classified as automation and will get you banned. Please avoid using any kind of delays in your scripts as not only will it get you banned but if Blizzard finds that people abuse AutoHotKey to achieve automation then they may decide to ban AutoHotKey altogether.

The rule of thumb is to ask yourself if what you do in your script can be achieve with an in-game macro. For example the auto-assist mechanism discussed below can be achieved in-game by macroing every ability and at the start of each macro adding an assist command.

Download

AutoHotKey is a free download available from the AutoHotKey Website

AutoHotKey Initial Setup

Installation

Download and install AutoHotKey from the official site AutoHotKey Website

Your first script

Create a new file with a ".ahk" extension, for instance "MyScript.ahk". Edit the file and enter the following:

#space::Run www.google.com

The "#" inside the script represents the windows key and "space" the space key. Save the script file and double

click on the file. You should notice a new tray icon and a new executable file which is your compiled script.

Now hold down the windows key and press space and Google should be launched.

Congratulations, you just wrote your first AutoHotKey script.

Key Broadcasting

Key broadcasting is our most basic requirement for multi-boxing and the reason we are using AHK in the first

place. AHK gives us a lot of tools to achieve key broadcasting so lets take a look at how to use them.

We will be using World of Warcraft in the example code but it should be easy enough to modify the code for

other applications.

Early exit

If one of our target windows is not currently active we can ignore processing of key presses. The following

command will halt execution of the script if a window with a title of "World of Warcraft" is not active.

; *** Only if WoW is in focus ***
#IfWinActive, World of Warcraft

The line above should be placed as early as possible in your script so we can avoid doing any unnecessary

processing.

Identifying windows

Before we can do any key broadcasting we need to identify the windows that we want to broadcast to. The

following command will retrieve a list of all the windows with a title of "World of Warcraft"

;Grab unique window ID's
WinGet, WowWinId, List, World of Warcraft

WowWinID now contains a list of all the window IDs with a title of "World of Warcraft". The above line should

be near the top of the script as well and before we do any key broadcasting.

Key broadcasting procedure

The simplest way to pass keys is to use a procedure to send keys to all the relevant windows. Broadcasting a

key will require just a single procedure call instead of passing the key to each relevant window. If you are 5-

boxing then passing a key requires at least 4 broadcast commands. Using a procedure we can cut it down to one

line.

ClonesPush(strKeys)
{
	global WowWinId1
	global WowWinId2
	global WowWinId3
	global WowWinId4
	global WowWinId5
	IfWinNotActive, ahk_id %WowWinId1%
		ControlSend, , %strKeys%, ahk_id %WowWinId1%
	IfWinNotActive, ahk_id %WowWinId2%
		ControlSend, , %strKeys%, ahk_id %WowWinId2%
	IfWinNotActive, ahk_id %WowWinId3%
		ControlSend, , %strKeys%, ahk_id %WowWinId3%
	IfWinNotActive, ahk_id %WowWinId4%
		ControlSend, , %strKeys%, ahk_id %WowWinId4%
	IfWinNotActive, ahk_id %WowWinId5%
		ControlSend, , %strKeys%, ahk_id %WowWinId5%
}

The procedure should be at the top of your script. If you are 2-boxing just remove all lines to do with

WowWinId3, WowWinId4 and WowWinId5.

The procedure does the following:

  • It maps WowWinId1 to WowWinId5 to the window IDs we retrieved in the "Identifying windows" section
  • It checks that a window is *not* active before sending the key (explanation below)
  • It sends the keys passed in the "strKeys" parameter using the ControlSend command

Why do we check that a window is not active? AHK allows us to pass all key presses through to the currently

active window (which we will be doing) and sending the key to the active window as well will result in the

active window getting the keypress twice. If you choose not to use AHK's pass-through feature then you can

safely remove the the active check.

Broadcasting a key

Now we are finally ready to start broadcasting keys. The following code should form part of the bottom of your

script. All code discussed above should precede the broadcast calls.

; *** Jump ***
~Space::ClonesPush("{Space down}{Space up}")

The "~" character tells AHK to pass the pressed key through to the active window. Inside the key broadcast

procedure we only send the key to inactive windows to prevent AHK from sending the key to our currently active

session twice. If you remove the "~" here you will need to remove the "IfWinNotActive" check from the key

broadcast procedure to get the key passed to your active window as well.

"Space::" tells AHK to execute the command that follows when the spacebar is pressed.

"ClonesPush("{Space down}{Space up}")" will send a spacebar down and a spacebar up message to all relevant

windows.

Movement

Movement is a little trickier than what we did above. Most movement is the result of holding a key down. When

you get your flying mount and you hold the spacebar down to make all your characters rise vertically you might

be disappointed.

In the case of movement we actually need to pass key down and key up messages separately.

; *** Jump ***
~Space::ClonesPush("{Space down}")
~Space Up::ClonesPush("{Space up}")

Here is an example of how to move all your non-active windows using the arrow keys:

; *** Move clones ***
Up::ClonesPush("{Up down}")
Up Up::ClonesPush("{Up up}")
Down::ClonesPush("{Down down}")
Down Up::ClonesPush("{Down up}")
Left::ClonesPush("{Left down}")
Left Up::ClonesPush("{Left up}")
Right::ClonesPush("{Right down}")
Right Up::ClonesPush("{Right up}")

Note the ommission of the "~" character. The above keys will only be passed to your non-active windows and will

not be passed to your active window. It basically allows you to move your clones independantly of your main.

Hotbars

Here is how to pass your main hotbar:

; *** Hotbars 1-0 ***
~1::ClonesPush("{1 down}{1 up}")
~2::ClonesPush("{2 down}{2 up}")
~3::ClonesPush("{3 down}{3 up}")
~4::ClonesPush("{4 down}{4 up}")
~5::ClonesPush("{5 down}{5 up}")
~6::ClonesPush("{6 down}{6 up}")
~7::ClonesPush("{7 down}{7 up}")
~8::ClonesPush("{8 down}{8 up}")
~9::ClonesPush("{9 down}{9 up}")
~0::ClonesPush("{0 down}{0 up}")

Targeting

Targeting is a major concern in any form of multi-boxing. AHK allows us to implement an auto-assist mechanism

relatively easily without the need to macro all of our abilities to include targeting.

The idea is to create a special key that you bind an assist macro to and to broadcast this key before

broadcasting the key that was pressed. An example assist macro can be:

/assist party1
/assist focus

Bind the assist macro to a key inside your WoW interface, for instance "=". Prepend all your broadcast keys

with "{= down}{= up}" effectively simulating an assist before using any commands.

Your hotbar broadcasting becomes:

; *** Hotbars 1-0 ***
~1::ClonesPush("{= down}{= up}{1 down}{1 up}")
~2::ClonesPush("{= down}{= up}{2 down}{2 up}")
~3::ClonesPush("{= down}{= up}{3 down}{3 up}")
~4::ClonesPush("{= down}{= up}{4 down}{4 up}")
~5::ClonesPush("{= down}{= up}{5 down}{5 up}")
~6::ClonesPush("{= down}{= up}{6 down}{6 up}")
~7::ClonesPush("{= down}{= up}{7 down}{7 up}")
~8::ClonesPush("{= down}{= up}{8 down}{8 up}")
~9::ClonesPush("{= down}{= up}{9 down}{9 up}")
~0::ClonesPush("{= down}{= up}{0 down}{0 up}")

Suspending AHK

Sometimes we do not want AHK to broadcast keys, when typing in chat channels for instance. The following script

commands give an example of how to enable/disable AHK processing.

~Enter::Suspend, Toggle

When ENTER is pressed AHK is toggled on and off, useful when hitting ENTER to type into the chatbox and hitting

ENTER again to send. AHK is suspended on the first ENTER and enabled again on the second ENTER.

~/::Suspend, On
~Escape::Suspend, Off

Whenever "/" is pressed we suspend AHK. Very useful when editing macros or if you are used to pressing "/" to

enter commands. ESC enables AHK so if you decide not to finish typing in the command box and you hit ESC then

AHK is enabled again and broadcasting keys.

Just remember to enable AHK after editing macros. If you entered a "/" in a macro it will disable AHK and if

you don't hit ENTER or ESC it will remain disabled. I have wiped once or twice on a boss when I fine tuned

macros for the encounter and engaged without checking that AHK is enabled.

~r::Suspend, On

If you are used to just hitting "r" to reply to tells then the above will allow you to do the same without

making your clones go crazy.

Example Script - Full

Here is an example script you can use to get started. It implements several of the techniques described above.

The script assumes that you have an assist macro bound to "=".

ClonesPush(strKeys)
{
	global WowWinId1
	global WowWinId2
	global WowWinId3
	global WowWinId4
	global WowWinId5
	IfWinNotActive, ahk_id %WowWinId1%
		ControlSend, , %strKeys%, ahk_id %WowWinId1%
	IfWinNotActive, ahk_id %WowWinId2%
		ControlSend, , %strKeys%, ahk_id %WowWinId2%
	IfWinNotActive, ahk_id %WowWinId3%
		ControlSend, , %strKeys%, ahk_id %WowWinId3%
	IfWinNotActive, ahk_id %WowWinId4%
		ControlSend, , %strKeys%, ahk_id %WowWinId4%
	IfWinNotActive, ahk_id %WowWinId5%
		ControlSend, , %strKeys%, ahk_id %WowWinId5%
}

;Grab unique window ID's
WinGet, WowWinId, List, World of Warcraft

; *******************************
; *** Only if WoW is in focus ***
; *******************************
#IfWinActive, World of Warcraft

;*** Special Functions ***

; *** Makes clones follow main ***
^-::ClonesPush("{- down}{- up}")

; *** Makes clones assist main ***
^=::ClonesPush("{= down}{= up}")

; *** Makes clones jump with main ***
~Space::ClonesPush("{Space down}{Space up}")

; *** Suspends HotKeys while typing on main ***
~Enter::Suspend, Toggle
~/::Suspend, On
~Escape::Suspend, Off

; *******************
; *** Hotbars 1-0 ***
; *******************
~1::ClonesPush("{= down}{= up}{1 down}{1 up}")
~2::ClonesPush("{= down}{= up}{2 down}{2 up}")
~3::ClonesPush("{= down}{= up}{3 down}{3 up}")
~4::ClonesPush("{= down}{= up}{4 down}{4 up}")
~5::ClonesPush("{= down}{= up}{5 down}{5 up}")
~6::ClonesPush("{= down}{= up}{6 down}{6 up}")
~7::ClonesPush("{= down}{= up}{7 down}{7 up}")
~8::ClonesPush("{= down}{= up}{8 down}{8 up}")
~9::ClonesPush("{= down}{= up}{9 down}{9 up}")
~0::ClonesPush("{= down}{= up}{0 down}{0 up}")

; ***************************
; *** Hotbars SHIFT(+) 1-0 ***
; ***************************
~+1::ClonesPush("{Shift down}{1 down}{1 up}{Shift up}")
~+2::ClonesPush("{Shift down}{2 down}{2 up}{Shift up}")
~+3::ClonesPush("{Shift down}{3 down}{3 up}{Shift up}")
~+4::ClonesPush("{Shift down}{4 down}{4 up}{Shift up}")
~+5::ClonesPush("{Shift down}{5 down}{5 up}{Shift up}")
~+6::ClonesPush("{Shift down}{6 down}{6 up}{Shift up}")
~+7::ClonesPush("{Shift down}{7 down}{7 up}{Shift up}")
~+8::ClonesPush("{Shift down}{8 down}{8 up}{Shift up}")
~+9::ClonesPush("{Shift down}{9 down}{9 up}{Shift up}")
~+0::ClonesPush("{Shift down}{0 down}{0 up}{Shift up}")

; **************************
; *** Hotbars CTRL(^) 1-0 ***
; **************************
~^1::ClonesPush("{Ctrl down}{1 down}{1 up}{Ctrl up}")
~^2::ClonesPush("{Ctrl down}{2 down}{2 up}{Ctrl up}")
~^3::ClonesPush("{Ctrl down}{3 down}{3 up}{Ctrl up}")
~^4::ClonesPush("{Ctrl down}{4 down}{4 up}{Ctrl up}")
~^5::ClonesPush("{Ctrl down}{5 down}{5 up}{Ctrl up}")
~^6::ClonesPush("{Ctrl down}{6 down}{6 up}{Ctrl up}")
~^7::ClonesPush("{Ctrl down}{7 down}{7 up}{Ctrl up}")
~^8::ClonesPush("{Ctrl down}{8 down}{8 up}{Ctrl up}")
~^9::ClonesPush("{Ctrl down}{9 down}{9 up}{Ctrl up}")
~^0::ClonesPush("{Ctrl down}{0 down}{0 up}{Ctrl up}")

Sample Script Collection

AutoHotKey Sample Script Collection

Credits

  • Sorn - most of the code samples are based on the original script created by Sorn
  • Splorygon - creator of the key broadcasting procedure and numerous refinements

Useful Links

Personal tools