Total Videos



These are the most common ask AHK questions.

How do I add to the FAQs

Just send over an email to me at

My script wont work with my video game


Window Spy: This is a basic standard, reveals system names, pixel colors, coordinates... Usually the only tool needed.

Send and Click Tester:

This tool will help you determine which click and send modes work with your game. Very useful!

Easy Steps:

First basic steps to get AHK working with the average game.

1) Make sure the script is running with Admin privilege(Right-Click on script, Run As Administrator)

-Explanation: Some games run at admin level and AHK does not typically run with this privilege set.

2) Switch the game settings from 'Full Screen' mode to 'Windowed' or (I prefer) 'Borderless Windowed' mode.

-Explanation: DirectX draws the screen in a manner different from Windows, this can cause things like colors

being reported wrong, mouse jumping to the 'wrong' coords, and it can just plain prevent the game from

registering the input at all.

3) A lot of times Keypresses need to be held down longer than normal for the game to fully register it.

-Explanation: Usually caused by DirectX(DirectInput). It 'polls' the keyboard every 15ms(varies slightly) and

records the keys that are down, then 15ms later it takes another 'snapshot' and compares the two. This

is how games allow you to hold two(or more) keys at the same time, but very fast(sub 10-15ms) inputs

can fall between snapshots and the game never sees the keypress. If your script is very twitchy and seems

to skip over some keypresses then this is likely the problem. Some games can require large delays, 50-100ms

or more in some select cases.

-Example: (Holds key down for 20ms)

Code: Select all - Toggle Line numbers

Send, {a down}
Sleep 20
Send, {a up}

4) Some games do not allow their keybinds to be 'hijacked'.

-Explanation: Many games, especially DirectX driven, use driver level keyboard interaction and cannot be

changed via AHK. You need to choose keybindings that the game is NOT using, some people have had

success by changing the in-game keybinds so that those keys are 'free' for AHK to use. Sometimes this

can be overcome by constantly rehooking the keyboard and mouse. An indicator that this is the case is

that the keys work once or 'for a while' and then stop working completely.

Intermediate Steps:

If you are at this point and the script still doesn't work it is likely that you are dealing with some sort of cheat

prevention software. Don't give up hope, there are a couple fairly simple things that can still be done.

1) Compile the script to .exe form and rename the program to something non-threatening to the game.

-Explanation: Look here in the docs for how to compile, it is very well written and I will not be re-creating

the wheel here. This method is a fairly simple workaround for most 'hackshield' type softwares.

-Examples: Rename to something generic or the same as something legit(setup.exe, skype.exe) possibly

just random garbage(alksjdu.exe).

2) Set up a second user account and run scripts as that user. Here is a link to the post with full explanation.

-Explanation: Games run as one user do not have access to the processes run by a second user. In

this scenario, some cheat prevention softwares lack the access level to prevent the keystrokes sent

by the second 'user'(our AHK script)

Expert Steps: (These well assume a high level of knowledge)

These will be very difficult in comparison to the above steps and will require in-depth knowledge to implement.

Typically this level of workaround is only necessary when trying to bypass a cheat detection system.

1a) Download and setup a VM(Virtual Machine), install and run the game INSIDE the VM. Run AHK on

the OUTSIDE OS. This should prevent the game from interacting directly with AHK or 'seeing' it while

still allowing AHK to move the mouse and click.

1b) Use a second computer to 'Remote Desktop' to the primary gaming PC, run AHK on 'outside' PC.

2) Simulating DirectInput. This is difficult and not supported natively in AHK in any way. Look here for a

thread describing a couple ways to simulate DirectInput. This is theoretical and untested. Requires

knowledge of DLL interaction.

3) Altering Autohotkeys mutex names. This requires downloading the Autohotkey C++ source code and altering certain names

that specific anti-cheat softwares look for. Namely XignCode and AhnLab. You will have to ask further about this in the forum

or on Reddit as this step basically requires a custom compiled version of Autohotkey.

Following these steps should get scripts working in the majority of games. I have found a few that I cannot

make work so far but they are few and far between. If you have some tips to add to this please let me know!

Holding Down a Key / Autofire

 Holding Down a Key / Autofire

How to make a key "autofire" when a key is held down.

Edit: Don't use loops/while-loops for auto-fire. The original method posted here was how I first learned. While it does work, I later learned it can cause problems in a script. Especially when 2 loops try to run at the same time.
The more appropriate way of doing this is to use SetTimer.

This example shows how to make the 'a' key fire the 'b' key repeatedly.

; The hook $ hotkey modifier prevents a hotkey from firing itself.

; If 'a' is the hotkey, and it sends 'a', it would keep looping


    ; Run the label AutoFireA

    GoSub, AutoFireA


; Label auto firing


    ; Send a key. We're using 'b'

    Send, b

    ; Check to see if 'a' is still being held down

    if GetKeyState("a", "P")

        ; If yes, set a timer to run this label again. Time is in ms

        ; Using a negative number fires the timer once instead of repeatedly.

        SetTimer, AutoFireA, -100


Hotkey Symbols

One Key Activates Two Others

One Key Activates Two Others

If you want to send multiple keystrokes from 1 key, this is how you do it:
Please make sure you read example #2 (above) for explanations of when to use ~ and $ at the beginning of a hotkey.

; When you press "a", the keys "b" and "c" are pushed 


 Send, bc



How do I save data / Settings

Option 1 - To a Text File:

; Numpad+ to add 1 to the counter



    ; There's no delete line for file append so you have to delete the whole file

    ; Then re-create it again to update the counter.

    ; %A_Temp% is a built in variable that points to your profile's temp folder

    FileDelete, %A_Temp%\counter.txt

    FileAppend, %counter%, %A_Temp%\counter.txt


; Numpad- to subtract 1 from the counter



    FileDelete, %A_Temp%\counter.txt

    FileAppend, %counter%, %A_Temp%\counter.txt



Built-In Variables

Option 2 - To a .ini File:

; Numpad+ adds 1 to the counter stored in the .ini file.



    ; There's no delete line for file append so you have to delete the whole file

    ; Then recrecreate it again to update the counter.

    IniWrite, %counter%, %A_Temp%\counter.ini, Counter Section, Counter


; Numpad- to subtract 1 from the counter stored in the ini file.



    IniWrite, %counter%, %A_Temp%\counter.ini, Counter Section, Counter


Built-In Variables

Option 3 - To a .ini section inside the script:

Note: This will not work for scripts compiled into executables.

;============================== Start Auto-Execution Section ==============================

; When the script starts, it reads the counter key of the SavedVariables section

; stored in this script. This helps "remember" the value of counter.

IniRead, counter, %A_ScriptFullPath%, SavedVariables, counter


;============================== Main Script ==============================

; Numpad+ adds 1 to the counter stored in the ini section at the end of this script.



    ; This will write the current counter to the counter key in the SavedVariables section

    ; of this script.

    IniWrite, %counter%, %A_ScriptFullPath%, SavedVariables, counter


; You can put your ini section inside of a multi-line comment.

; Start with a /* and end with a */


This is an ini saved variable section.

You can write whatever you want here because AHK sees it as a comment.

Anything [insideBrackets] starts a new section. This is what the script looks for when dealing with ini files.




;============================== End Script ==============================

Built-In Variables

Starting/Stopping Things (Loops vs SetTimers)

Loops are great when you know you want something to run infinitely or want it to run a set number of times. But for starting and stopping a script, SetTimer is a much better choice over Loops with breaks.

With SetTimer, you can make very easy On/Off hotkeys, and you have control over how often the loop happens.

This script makes a message box that says "Hello!" pop up every 20 seconds.
F1 starts it. F2 stops it.

; Start timer. It'll run the helloPopUp label every 20 seconds.


    SetTimer, helloPopUp, 20000


; Stop the popup timer.


    SetTimer, helloPopUp, Off



    MsgBox Hello!



Here's an example of the same script using a loop with an if-break statement. It works the same, but it's bulky and sometimes the breaks don't quite work like you want them to. That's why I advise people to use SetTimers unless the loop needs to run forever or run a certain amount of times.


    breaker := false



        if (breaker = true){



        Sleep, 20000

        MsgBox Hello!




    breaker    := true



Finding Out What Button You're Pressing (JoyPad, Random Keyboard Keys, Surface Pro Stylus, etc...)

A lot of times, people need to find out how to use a specific button. It might be on a controller, or it might be some extra mouse button or an extra key on your keyboard. We also see a lot of Surface Pro Stylus questions. So here a couple ways to help you identify what button you're pressing.
It should be noted that NOT ALL BUTTONS/KEYS CAN BE DETECTED!!! Remember that.

Option 1 - Keyboard Hook Method

Make this into a script:




Now double-click on the script icon in your system tray (Or right-click then click "Open").

Click "View" then "Key History and Script Info".

You can now press whatever buttons you're trying to identify. Press them a few times, then press F5 to refresh the Key History.
I chose to click my left mouse button and then type "autohotkey"

You should see something like this:

Window: D:\Scripts\AHK\Del.ahk - AutoHotkey v1.1.23.01

Keybd hook: yes

Mouse hook: yes

Enabled Timers: 0 of 0 ()

Interrupted threads: 0

Paused threads: 0 of 0 (0 layers)

Modifiers (GetKeyState() now) = 

Modifiers (Hook's Logical) = 

Modifiers (Hook's Physical) = 

Prefix key is down: no

The oldest are listed first.  VK=Virtual Key, SC=Scan Code, Elapsed=Seconds since the previous event. 

Types: h=Hook Hotkey, s=Suppressed (blocked), i=Ignored because it was generated by an AHK script,

a=Artificial, #=Disabled via #IfWinActive/Exist, U=Unicode character (SendInput).

VK  SC    Type    Up/Dn    Elapsed    Key        Window


01  000         d    1.19    LButton            

01  000         u    0.05    LButton            

41  01E         d    1.50    a                  

41  01E         u    0.11    a                  

55  016         d    0.16    u                  

55  016         u    0.08    u                  

You can use those VKs (virtual keys) and SCs (scan codes) in a script now. If I wanted my "a" key to make a message box pop up, I can do it with the VK or the SC like this:


   MsgBox VK Hello! 




  MsgBox SC Hello! 



Making Certain Things Only Work in Specified Programs (WindowSpy!)

If you want your hotkeys/hotstrings/any other part to only work in a specific program, you'll need the #IfWinActive command.

To make a hotkey that only works in Chrome, we can use the following:

; Everything following #IfWinActive will only work for the program specified.

#IfWinActive, ahk_exe chrome.exe

; Opens a new tab and searches for "autohotkey tutorial"


    Send, ^t

    Sleep, 100

    Send, autohotkey tutorial{enter}


; The second #IfWinActive is to indicate anything past this

; point will work in any program.


If you're confused about the ahk_exe part, don't be. It's just one of many ways to identify a window.

You can use the title, but this can cause problems as titles can change. If you feel you NEED to use the title of the program, you can set HOW it searches for titles by using SetTitleMatchMode.

Most of the time you should use either the ahk_exe or the ahk_class.

To find a program's class or exe, you can use a powerful tool called "WindowSpy" that was installed along with AutoHotkey. To open window spy, run a script, right-click on the script icon in your system tray and click "Window Spy".

There's also a button for it in SciTE4AutoHotkey. Look on the bottom toolbar, right side.

WinTitle (Covers ahk_exe, ahk_class, ahk_id , ahk_pid, ahk_exe, ahk_group)

Sending a Keystroke or Mouse Event to an Inactive Window

Sometimes you need to send a keystroke or mouse click to a program that's not active. Like playing/pausing your music player when you're in the middle of a game. Or maybe you need to pause the movie that's playing on your second monitor.
To do that, you'll need to use ControlSend or ControlClick.

Here's my own personal script I use to control WinAmp (a music player) regardless of what program is active.

;============================== Winamp ==============================

#IfWinExist, ahk_exe winamp.exe

; Previous Song


    ControlSend, ahk_parent, z, ahk_class Winamp v1.x


; Play


    ControlSend, ahk_parent, x, ahk_class Winamp v1.x


; Pause


    ControlSend, ahk_parent, c, ahk_class Winamp v1.x


; Next Song


    ControlSend, ahk_parent, b, ahk_class Winamp v1.x



It should be noted that the ahk_parent part (called the control parameter) is not usually needed. Winamp is one of the rare cases where it's required. Normally you'll leave it blank like this:

    ControlSend, , a, ahk_exe notepad.exe


How do I create a toggle with a single key?

If you're looking for a way to toggle things on and off, here's how you make a toggle using a variable.

;While you don't have to declare the toggle, by doing so you know what the initial start value is

toggle:= 0


F1:: ; This is where the toggling occurs. You're setting the toggle to the opposite of itself. ; 1 becomes 0. True becomes False. You can use either. toggle := !toggle

if (toggle = 0)

; If the toggle is off (0 or false), do the stuff in here MsgBox, The toggle is turned off. 


; If the toggle is on (1 or true), do the stuff in here MsgBox, The toggle is turned on. 



If (expression)

Game Info List

All the facts we know so far for gaming with AHK

Add A Game

Just send over an email to with the games name and details

A - F

Diablo 3

- Likes a small sleep between up/down events

- Use windowed mode

- Does pretty good with rapid keypresses


-Very Limted on what you can do

-Is aginst there TOS so could be banned. (they do have bots if you run your own server)


-Single key maps are ok

-more then that will get account banned

Final Fantasy XI

- Generally needs #UseHook

- Windows 10 user need to start script in administrator mode enabled as the game need to be in administrator mode as well to run.

G - L


-Works fine in single player but multi can get you banned but seems rare

-Will not work when running from a macro creator

League of Legends:

- Likes a sleep between up/down events

- Use windowed mode

M - R


-Works well

-pixel and image search very poor as blocks randomize particles

-Bans come from server host so up to them

Path of Exile

- Requires a delay between moving the mouse and doing the actual click, otherwise it will click at

current position then move the mouse to the coordinates.


-Works well but sleeps are needed between sends and clicks. sleep 250 seems to work fine. No reports of banning for automating button press

-Can be banned for creating chat spamming bots.

-Contralsend or Contralclicks will not work. Game needs to be active window

S -Z

South Park: The Stick of Truth:

- Requires regular reinstatements of #UseHook

This game regularly overrides key hooks causing working scripts to stop working until reloaded


-Works well as long in you are in window mode

-Known for banning AHK so need to complie script 


-Works well. Some sends may need a small sleep between each one

-Bans come from server host so up to them.


- Works well

-Known for banning people using AHK best to compile.

World of Warcraft

-Works well but very big on banning. Most peoples accounts will get banned with in a month or two and they 

will not unban you. The AI is one of the best in looking for automating scripts.

0 - 9

None Yet

Will Not Work With AHK

Wolfenstein: The New Order