[GUIDE] Optimize AutoHotkey timing

03/25/2016 18:44 WAZAAAAA...#1
INSTRUCTIONS:
Just copy the following code at the top of your scripts:
Code:
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
and replace your Sleep commands with this:
Code:
DllCall("Sleep","UInt",INSERT_MILLISECONDS_HERE)


EXPLANATION:
Video games in particular may require high precision inputs. The above optimizations are aimed at making your AutoHotkey scripts more accurate, I will now describe why:

The default sleep command used by AutoHotkey has limited precision:
- sleeping below 10 or 15 milliseconds is not possible
- whatever number you use will not be precise (your script may sleep less or more than the value you've set)

Some default settings will also add more sleep time:
- default SetBatchLines makes your script sleep 10 milliseconds every line!
- default SendEvent is slower than SendInput
- in case SendEvent must be used, various parameters such as SetKeyDelay, SetMouseDelay and SetDefaultMouseSpeed will all add delays
- depending on your script, optimizing SetWinDelay and SetControlDelay may help too

There are other ways to slightly reduce the CPU load and increase process priority too:
- disabling environment variables
- disabling key history
- changing process priority to High

Other useful code is included too:
- the two "Interval" commands exist to make fast key presses work smoothly with no popup interruption
- auto-detect if the script is running as Administrator or not
- adding $* before an hotkey will ensure it works correctly in most of the games

Additional information from the official AutoHotkey forums can be found here (such as testable benchmarks and PixelSearch "Fast" parameter being slower than default if you only search for 1 pixel of 1 color): autohotkey.com/boards/viewtopic.php?f=6&t=6413



EXAMPLE:
This is a working optimized "Instant WallJump" macro designed for S4 League. You can save it as as ANYTHING.AHK to give it a try.
Hold LEFT ALT to mash SPACEBAR every ingame frame. Because S4 runs at 62.5 FPS... 1000 milliseconds ÷ 62,5 frames = 16 milliseconds to sleep (+ 0,1 since it's always good to add some leniency).
Press INS to enable/disable the script.
Code:
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input

$*LAlt::
Loop
{
	if not GetKeyState("LAlt","P")
		break
	Send {Space Down}
	DllCall("Sleep","UInt",16.1)
	Send {Space Up}
	DllCall("Sleep","UInt",16.1)
}
return

$*Ins::Suspend


WARNING:
Using the alternative sleep I posted will conflict with SetTimer if you're using such command.
If you're running a loop with these optimizations, ALWAYS sleep somewhere, otherwise your script would send keys too fast for your computer to handle.
03/26/2016 01:11 ahmed1234550#2
thanks dude its really useful

Edit: if i need to set my macro to 13 milliseconds i have to change 16.1 to 13.1? just like this ?
DllCall("kernel32.dll\Sleep", "UInt", 13.1)
03/26/2016 05:17 WAZAAAAA...#3
Quote:
Originally Posted by ahmed1234550 View Post
thanks dude its really useful

Edit: if i need to set my macro to 13 milliseconds i have to change 16.1 to 13.1? just like this ?
DllCall("kernel32.dll\Sleep", "UInt", 13.1)
If you want to sleep for 13 ms just put 13. If you have a game that runs at 77 FPS, I guess that 13.1 would be better.

The 16.1 is there because an ingame frame lasts 16 milliseconds, so adding that +0.1 ensures that S4 will NOT skip your input. For example, if I made the example script sleep for 8 instead of 16.1, half of the inputs would be ignored by the game because they happen too fast, and the macro would be terrible.

Maybe if you play a random game in slow motion frame by frame, you would understand what I'm trying to say better... but you can always try. Cheat Engine speedhack at 0.02, you will have to hold buttons for a lot of time to let the game register them, more specifically until the NEXT FRAME.
03/27/2016 12:47 GalaxyCMS123#4
Could you help me making a bot that can be able to stun stabs like speedcounter against dash?Only problem is the delay.
03/27/2016 17:45 ahmed1234550#5
can you share your dash cancel code plz ? or just make one for me :c
03/28/2016 08:28 WAZAAAAA...#6
Quote:
Originally Posted by GalaxyCMS123 View Post
Could you help me making a bot that can be able to stun stabs like speedcounter against dash?Only problem is the delay.
Even with perfect execution, it's not really possible to SpeedCounter very fast combos such as Spy Dagger or Plasma Sword Dashes, because you have to take into account the LAG. Maybe you could pull it off in an offline/LAN situation, lol.
But still, here's a macro I made a while ago if you want to try:
Works best with a Counter Sword or Twin Blade (on slot 2) because they have the fastest SpeedCounters on left click ( [Only registered and activated users can see links. Click Here To Register...] ).
F = executes SpeedCounter
Ins = enable/disable
Code:
#InstallMouseHook
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
if not A_IsAdmin
{
	MsgBox, You are running this script with no administrator rights. It may not work.
}

$*f::
;ensuring that the player doesn't interfere with the macro
Send {SC011 Up} ;W
Send {SC01E Up} ;A
Send {SC01F Up} ;S
Send {SC020 Up} ;D
Send {Click Right Up}
;the actual inputs
Send {Space Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {Space Up}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {SC020 Down}
Send {Space Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {Space Up}
Send {SC020 Up}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {2 Down}
Send {Click Left Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {Click Left Up}
Send {2 Up}
;ensuring that the macro doesn't interfere with the player
if GetKeyState("SC011","P")
	Send {SC011 Down}
if GetKeyState("SC01E","P")
	Send {SC01E Down}
if GetKeyState("SC01F","P")
	Send {SC01F Down}
if GetKeyState("SC020","P")
	Send {SC020 Down}
if GetKeyState("RButton","P")
	Send {Click Right Down}
return

$*Ins::Suspend
Quote:
Originally Posted by ahmed1234550 View Post
can you share your dash cancel code plz ? or just make one for me :c
What does "dash cancel" mean? Be more specific.
03/28/2016 10:01 GalaxyCMS123#7
Quote:
Originally Posted by WAZAAAAA... View Post
Even with perfect execution, it's not really possible to SpeedCounter very fast combos such as Spy Dagger or Plasma Sword Dashes, because you have to take into account the LAG. Maybe you could pull it off in an offline/LAN situation, lol.
But still, here's a macro I made a while ago if you want to try:
Works best with a Counter Sword or Twin Blade (on slot 2) because they have the fastest SpeedCounters on left click ( [Only registered and activated users can see links. Click Here To Register...] ).
F = executes SpeedCounter
Ins = enable/disable
Code:
#InstallMouseHook
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
if not A_IsAdmin
{
	MsgBox, You are running this script with no administrator rights. It may not work.
}

$*f::
;ensuring that the player doesn't interfere with the macro
Send {SC011 Up} ;W
Send {SC01E Up} ;A
Send {SC01F Up} ;S
Send {SC020 Up} ;D
Send {Click Right Up}
;the actual inputs
Send {Space Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {Space Up}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {SC020 Down}
Send {Space Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {Space Up}
Send {SC020 Up}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {2 Down}
Send {Click Left Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.1)
Send {Click Left Up}
Send {2 Up}
;ensuring that the macro doesn't interfere with the player
if GetKeyState("SC011","P")
	Send {SC011 Down}
if GetKeyState("SC01E","P")
	Send {SC01E Down}
if GetKeyState("SC01F","P")
	Send {SC01F Down}
if GetKeyState("SC020","P")
	Send {SC020 Down}
if GetKeyState("RButton","P")
	Send {Click Right Down}
return

$*Ins::Suspend
What does "dash cancel" mean? Be more specific.
Don't you think would be better "s" instead of "d" because when you hold it with sp it dodges instead of speeding it, so it would work only when you are without sp and stunned, or i'm wrong?@WAZAAAAA...
PS: are you italian?:o
03/28/2016 10:08 WAZAAAAA...#8
Quote:
Originally Posted by GalaxyCMS123 View Post
Don't you think would be better "s" instead of "d" because when you hold it with sp it dodges instead of speeding it, so it would work only when you are without sp and stunned, or i'm wrong?@WAZAAAAA...
PS: are you italian?:o
sė lo sono e non ho capito una sega di quel che hai scritto
In uno SpeedCounter serve sempre l'input di un Dodge (A o D + Spazio), sia con SP che senza. Forse ti riferisci a qualcos'altro tu.
03/28/2016 14:45 ahmed1234550#9
if someone hit me with ps, dash i cancel it and change my weapon and block it with cs also dagger cancel, you know what i mean?
sorry for my english :D
03/29/2016 12:17 WAZAAAAA...#10
Quote:
Originally Posted by ahmed1234550 View Post
if someone hit me with ps, dash i cancel it and change my weapon and block it with cs also dagger cancel, you know what i mean? like this video
sorry for my english :D

[Only registered and activated users can see links. Click Here To Register...]
Quote:
Originally Posted by GalaxyCMS123 View Post
Could you help me making a bot that can be able to stun stabs like speedcounter against dash?Only problem is the delay.
Guys, this thread was supposed to help you build your own macros more efficiently, yet you're asking me to do all that shit for you...

...k

Here's my optimized SpeedCounter with Revenge (or "dash cancel" according to ahmed1234550 lol) that you've been asking for. The best part about it is that it has no "requirement": there's no need to change weapon, click anything, or release WASD directions. The macro should handle everything automatically.
For example, you can physically hold S+D+RightClick, while equipping a Submachine Gun, and the macro would STILL correctly switch to CS and input the Revenge SpeedCounter.
COMMANDS:
Mouse wheel (no need to hold it) = SpeedCounter
Ins = script ON/OFF
Code:
#InstallMouseHook
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
if not A_IsAdmin
{
	MsgBox, You are running this script with no administrator rights. It may not work.
}

$*MButton::
;ensuring that the player doesn't interfere with the macro
Send {SC011 Up} ;W
Send {SC01E Up} ;A
Send {SC01F Up} ;S
Send {SC020 Up} ;D
;the actual inputs
Send {Space Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.5)
Send {2 Down}
Send {Click Right Down}
Send {Space Up}
DllCall("kernel32.dll\Sleep", "UInt", 16.5)
Send {2 Up}
Send {SC020 Down}
Send {Space Down}
DllCall("kernel32.dll\Sleep", "UInt", 16.5)
Send {Space Up}
Send {SC020 Up}
;ensuring that the macro doesn't interfere with the player
if GetKeyState("SC011","P")
	Send {SC011 Down}
if GetKeyState("SC01E","P")
	Send {SC01E Down}
if GetKeyState("SC01F","P")
	Send {SC01F Down}
if GetKeyState("SC020","P")
	Send {SC020 Down}
DllCall("kernel32.dll\Sleep", "UInt", 350)
if GetKeyState("RButton","P")
	Send {Click Right Down}
else
	Send {Click Right Up}
return

$*Ins::Suspend
WARNING: you will most likely fail at SpeedCountering Dash attacks unless the attacker has very low ping to you, because they are too fast. CS needs to be on slot 2.

If you know about a better approach, let me know.
03/30/2016 00:57 ahmed1234550#11
this code works better for me and i tried it, works fine with dash cancel and dagger cancel but little slow
ur code more faster but sometimes bot ignore my click
check this code if u can edit something to make it better
PHP Code:
3 downcs
16.1
3 up
cs
16.1
S down
16.1
SPACE down
16.1
S up
16.1
SPACE up
16.1
D down
16.1
SPACE down
16.1
D up
16.1
SPACE up
RButton down
450
RButton up 
im using SendInput not Send

Edit: btw i change ur code to cs 3 is there any different?
03/30/2016 01:38 WAZAAAAA...#12
...why are you pressing S?

Quote:
Originally Posted by ahmed1234550 View Post
Edit: btw i change ur code to cs 3 is there any different?
it's ok
03/30/2016 01:43 ahmed1234550#13
Quote:
Originally Posted by WAZAAAAA... View Post
...why are you pressing S?

it's ok
idk lol i do dash cancel without macro, only space d+space i dont use s
but i think if u dont have sp better s idk why xd
but dude, yes with s better cuz my code have s works better xD
without s sometimes ignore my click