How to Make AHK Work in Most Games - The Basics

Helpful script writing tricks and HowTo's
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

How to Make AHK Work in Most Games - The Basics

04 Dec 2015, 18:12

Since this question gets asked a lot on the boards, with many many good suggestions and tips scattered everywhere, I decided to try to compile most of it in one place. I am looking forward to adding suggestions to this post so let me know what works and what doesn't! I will edit this post with notes on specific games as I see them here or from personal experience. I use AHK with most of the games that I play, anything from keybinds to full MMO grind bots. Lets compile some of our good info here.

If you have questions I can be reached on reddit, u/ThrottleMunky

Last Updated: 1-25-2023

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

Send and Click Tester: https://autohotkey.com/board/topic/95653-send-and-click-tool-v32/
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, although this can
vary depending on how the game is programmed. For example fighting games typically have the polling time
locked to the framerate to keep them synced for frame accurate actions. In games with highly variable frame
rates it is typically a set time, usually 10ms or 15ms. DirectInput operates by taking a state snapshot
all the keys that are pressed, then 15ms(or 1 frame) later it takes another 'snapshot' and compares the two.
This is how the game knows what was pressed, what was released and what is still being held down.
           It is also 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

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.
     -Example:
          This goes at the top of your script in the auto execute section.

Code: Select all

SetTimer, Rehook, 500
          This part goes at the bottom of your script.

Code: Select all

Rehook:
       #InstallKeybdHook
 return
 
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!



Tips for Specific Games
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.

League of Legends:
- Likes a sleep between up/down events
- Use windowed mode

Diablo 3:
- Likes a small sleep between up/down events
- Use windowed mode
- Does pretty good with rapid keypresses

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

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.

Code: Select all

MouseMove %VarX%, %VarY%
Sleep 50
Click



AHK Does Not Work In These Games(As far as I know, will be updated with solutions as they are found/suggested):
 
Wolfenstein: The New Order
Last edited by Ruevil2 on 25 Jan 2023, 10:46, edited 12 times in total.
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: How to Make AHK Work in Most Games - The Basics

06 Dec 2015, 09:00

nice tips!
and some security softwares like XignCode and AhnLab block the running of AutoHotkey through checking AutoHotkey's mutex name(default, AHK_KEYBD, AHK_MOUSE). Changing these values in script.cpp and compiling new AutoHotkey resolve the issue!
AutoHotkey & AutoHotkey_H v1.1.22.07
User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Contact:

Re: How to Make AHK Work in Most Games - The Basics

06 Dec 2015, 09:37

Also here is the old Topic on this also:
https://autohotkey.com/board/topic/1117 ... he-basics/

also you can try this tool,it tests different Send and Click Tool commands:
https://autohotkey.com/board/topic/9565 ... -tool-v32/
:yawn:
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: How to Make AHK Work in Most Games - The Basics

07 Dec 2015, 11:40

Lol I wrote the old topic, just wanted it to stay active after the old forum goes into archive and no more replies can be posted.

Edit: Added link to Snowflake's send and click tester tool.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: How to Make AHK Work in Most Games - The Basics

17 Dec 2015, 15:18

Some games require even longer to register keys. eg last time I checked Mechwarrior Online, it required 50ms. The line I always used in MWO scripts was SetKeyDelay, 0, 50. A nice trick that I worked out is that if the game has a chat window or some other way you can enter text, if the sent keys appear in the chat box, but do not trigger game actions, then key delay is most likely your problem.
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How to Make AHK Work in Most Games - The Basics

11 Mar 2016, 15:24

Im not sure if im using this post right but here goes

Final Fantasy XI:
- Gennerally 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.
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: How to Make AHK Work in Most Games - The Basics

15 Mar 2016, 11:08

Thanks for the tips Sven. Added and updated post!
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How to Make AHK Work in Most Games - The Basics

27 Mar 2016, 16:31

Another tip

Path of Exiled:
You have to put in a delay between moving the mouse and doing the actual click, otherwise it will click at current position and move the mouse to the cords.
Click %VarX%, %VarY%
Does not work correctly.

Instead you need to use mousemove and then the click command.
MouseMove %VarX%, %VarY%
Sleep 50
Click
Works perfectly.
User avatar
Hajin
Posts: 51
Joined: 13 May 2016, 09:16

Re: How to Make AHK Work in Most Games - The Basics

09 Jul 2016, 15:29

Yes, exists some cases that is needed a delay between the commands of the script, like in some emulators(maybe all).
Good topic, i saw one detail(that i had forgotten), that helped me now in a thing here.
Last edited by Hajin on 11 Jun 2023, 23:55, edited 1 time in total.
zbot_z
Posts: 2
Joined: 19 Aug 2017, 06:33

Re: How to Make AHK Work in Most Games - The Basics

21 Aug 2017, 09:18

worth bookmarking
Guest

Re: How to Make AHK Work in Most Games - The Basics

22 Aug 2017, 05:43

Soft wrote:nice tips!
and some security softwares like XignCode and AhnLab block the running of AutoHotkey through checking AutoHotkey's mutex name(default, AHK_KEYBD, AHK_MOUSE). Changing these values in script.cpp and compiling new AutoHotkey resolve the issue!
Hi Soft,

Where do you find this mutex names ? "D:\Program Files\AutoHotkey" I have just .ahk files and exe's
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: How to Make AHK Work in Most Games - The Basics

22 Aug 2017, 08:02

Guest wrote:
Soft wrote:nice tips!
and some security softwares like XignCode and AhnLab block the running of AutoHotkey through checking AutoHotkey's mutex name(default, AHK_KEYBD, AHK_MOUSE). Changing these values in script.cpp and compiling new AutoHotkey resolve the issue!
Hi Soft,

Where do you find this mutex names ? "D:\Program Files\AutoHotkey" I have just .ahk files and exe's
This process requires downloading the source code for Autohotkey, which is written in C++ I think, modifying it slightly and then recompiling it.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to Make AHK Work in Most Games - The Basics

20 Nov 2017, 17:49

In my testing with a handful of games, I've found that it mostly comes down to what I have SetKeyDelay set to. One game requires SetKeyDelay, 0, 1... three require SetKeyDelay, 0, 10... and another requires SetKeyDelay, 0, 40.

I suggest first trying SetKeyDelay, 0, 10

If that doesn't work, try SetKeyDelay, 0, 50

If that works, then try settings in between (ex. try SetKeyDelay, 0, 30 next) until you find the minimum values needed, so that you're not introducing longer delays than you need to.

Also, you may just want to use SetKeyDelay, 0, 50 while you're writing so script, so that you're not confusing this problem with your script not working. Later, when you're putting your finishing touches on your working script, you can dial down the value to the minimum that you need.
JonsG
Posts: 1
Joined: 17 Dec 2017, 17:54

Re: How to Make AHK Work in Most Games - The Basics

17 Dec 2017, 18:24

Hi all !
I made this script a while back for blackjacking. is it legal? :roll: Click right Return

s:: Mousemove,0,40,0,R Return

d:: Click Return

f:: Mousemove,0,-40,0,R Return

q:: Click right Return

w:: Mousemove,0,70,0,R Return

e:: Click Return

r:: Mousemove,0,-70,0,R Return

Esc::ExitApp

basicly to knock them out i press asdf and to pickpocket i press qwer
Cheers
Goon

Re: How to Make AHK Work in Most Games - The Basics

11 Feb 2018, 09:23

How can i run a macro like below while i press the shift button?

~Shift::
Send, 123456
Return

doesnt work
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: How to Make AHK Work in Most Games - The Basics

11 Feb 2018, 12:02

It should work.
Or try
~+::

Shift key. As a hotkey (Shift::) it fires upon release unless it has the tilde prefix. Corresponds to the + hotkey prefix.
from:
https://autohotkey.com/docs/KeyList.htm
:)

Edit: a little more info would also be nice.
Where did you try it (what program);
Did you try it in a notepad and see if it shows there;
What solutions from this post did you try;
What input mode are you using;
Did you try Run in admin mode;
etc. xD
Guest_user457

Re: How to Make AHK Work in Most Games - The Basics

12 Mar 2018, 04:20

You think this could walk for text based online games ?
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to Make AHK Work in Most Games - The Basics

14 Aug 2018, 22:06

In fullscreen DirectX games, if you try to take a screenshot or use the PixelGetColor, PixelSearch or ImageSearch commands, you may find (depending on the video card that you have) that they don't work and return only the color black or only the color white. All of those do work if the game is in windowed mode, but not in fullscreen mode.

An easy workaround is to use borderless windowed mode instead of fullscreen mode. To do that, run the game in windowed mode (ideally, at your desktop resolution) and execute the following lines:

Code: Select all

WinSet, Style, -0xC40000, A				; Remove title bar and border
WinMove, A,, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%	; Move and resize window to mimic fullscreen mode
That gives you the look of fullscreen mode, but allows for all commands and code to read the screen.

Note: If a game doesn't support windowed mode, doesn't support 3D acceleration in windowed mode or you can't get it to work, try the dgVoodoo 2 wrapper and choose Windowed on the main tab of the dgVoodoo Control Panel.
Work
Posts: 1
Joined: 17 Oct 2018, 16:27

Re: How to Make AHK Work in Most Games - The Basics

09 Oct 2019, 10:59

Has anyone tried use such tricks in games like Rust or with use easy game sheat?
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: How to Make AHK Work in Most Games - The Basics

05 Feb 2020, 12:41

Updated:

-Formatting
-Updated intermediate tricks
-Added new game suggestions

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 29 guests