Quantcast
Channel: Tech Talk — shoryuken
Viewing all articles
Browse latest Browse all 5515

Optimize your AutoHotkey macro scripts.

$
0
0
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 is that all of these changes makes the script use more CPU, so this isn't made for everyone.
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, like in the example script.

Just copy this at the beginning of any AHK script: http://pastebay.net/pastebay.php?dl=1408930
Writing this here in SRK too just in case.
#NoEnv
#KeyHistory 0
#MaxThreads 255
#MaxMem 4095
#MaxThreadsBuffer On
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
ListLines Off
Process, Priority, , R
SetTitleMatchMode fast
SetBatchLines, -1
SetKeyDelay, -1, -1, -1
SetMouseDelay, -1
SetWinDelay, -1
SetControlDelay, -1
SetDefaultMouseSpeed, 0
sleep(period := 1, Mode := "P")
{
	static Frequency, MinSetResolution, PID
	if (Mode = "P")
	{
		pBatchLines := A_BatchLines
		SetBatchLines, -1
		if !Frequency
			DllCall("QueryPerformanceFrequency", "Int64*", Frequency)
		DllCall("QueryPerformanceCounter", "Int64*", Start)
		Finish := Start + ( Frequency * (period/1000))
		loop 
			DllCall("QueryPerformanceCounter", "Int64*", Current)
		until (Current >= Finish)
		SetBatchLines, %pBatchLines%
	}
	return
}


; EXAMPLE SCRIPT! Hold X to mash Z every 16.6 milliseconds (= 1 frame) until X is released
$*x::
loop
{
if not getkeystate("x","p")
break
send {z down}
sleep(16.6, "P")
send {z up}
sleep(16.6, "P")
}
return
$*ins::exitapp
There are also two other ways to increase performance on AHK in general according to documentations:
1. Installing the Unicode x64bit version of AHK is better;
2. SendMode Input is better than the default SendMode Event. From my experience, it's the complete opposite, Input and Play are unresponsive as shit so I stick to the default one. Feedbacks of this would be appreciated.



Let me know if this actually helped.

Viewing all articles
Browse latest Browse all 5515

Trending Articles