How to Make AHK Work in Most Games - The Basics

Helpful script writing tricks and HowTo's
Ruevil2
Posts: 119
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.
 
Tools:
Send and Click Tester: https://autohotkey.com/board/topic/9565 ... -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(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)

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.
      
 
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: (None of these are verified or easy to use)
These are mostly theory at this point. These will be very difficult and will require in-depth knowledge to implement.
   (if you try any of these ideas with success let me know, i will update this)
 
1) 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.
 
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 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 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


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 22 Aug 2017, 08:17, edited 4 times in total.
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
GitHub: visionary1
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: 365
Joined: 28 Apr 2015, 05:41
Google: floowsnaake
GitHub: floowsnaake
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: 119
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: 3574
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: 255
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: 119
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: 255
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: 32
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. :D
____________________________________________________________________________________

Can anyone help me here?
https://autohotkey.com/boards/viewtopic.php?f=18&t=17798

My Scripts In This Forum:

____________________________________________________________________________________
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: 119
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: 53
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.

Return to “Tutorials”

Who is online

Users browsing this forum: Drugwash, Hellbent and 8 guests