Optimize your AutoHotkey macro scripts


If you use AutoHotkey and you’re having problems with tool assisted stuff because of timing inconsistencies, I want to tell you about all the possible optimizations that can be done to AHK scripts that I know of. Those include the removal of “hidden” and “obscure” delays, the deactivation of unnecessary functions, giving more “CPU attention” to the macro, the removal of silly limitations, and most importantly an high precision Sleep function. The only downside to the advanced Sleep function is that it makes the script use more CPU.
If the QPC Tick Tests I did with AHK didn’t lie to me, the sleep function is supposed to be tremendously precise, like microsecond precise. Just remember that you have to use the precise sleep function every time you need to sleep in your script, like in the example script.

Original discussions on the AHK forum: http://ahkscript.org/boards/viewtopic.php?f=6&t=6413
The code you need to slap at the top of your scripts:

#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H ;if unstable, comment or remove this line
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
;YOUR SCRIPT GOES HERE, but first some recommendations
;the Unicode x64bit version is the fastest AHK installation
;use PixelSearch without Fast if you're searching for a single pixel of a single shade
;use the precise sleep function in the example to wait exactly 16,67 milliseconds
; EXAMPLE SCRIPT! Hold X to mash Z every 16.67 milliseconds (= about 1 frame) until X is released, press Ins to exit
if not getkeystate("x","p")
send {z down}
DllCall("Sleep", UInt, 16.67)
send {z up}
DllCall("Sleep", UInt, 16.67)


Let me know if this actually helped.


Nice to know, thanks for the info. I’ve answered your post on my page btw, it’s about another method of making accurate scripts. I’ve also included some examples. For anyone wondering: