Trying to fix a slight delay that occurs with key bindings

Ask gaming related questions (AHK v1.1 and older)
Tcjenkens
Posts: 12
Joined: 31 Aug 2018, 17:43

Trying to fix a slight delay that occurs with key bindings

20 Mar 2019, 21:53

So I am playing Diablo 2. Typically you cast abilities using the right mouse click. I have used ahk so that I can press keyboard keys and it will cast abilities instead. Also if you hold the key down it will repeatedly cast the ability. What the issue is, is when I hold the key down to repeatedly cast the ability it does an initial ability cast, pauses briefly, then precedes to spam the ability without pause. Is there a reason there is an initial pause.

This is my code.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; Press the Q key and click and un-click the right mouse button
Q::
if ( not GetKeyState("RButton" , "P") )
Send {Q}
Sleep, 0
Click down right
Click up right
return

; Press the W key and click and un-click the right mouse button
W::
if ( not GetKeyState("RButton" , "P") )
Send {W}
Sleep, 0
Click down right
Click up right
return

; Press the E key and click and un-click the right mouse button
E::
if ( not GetKeyState("RButton" , "P") )
Send {E}
Sleep, 0
Click down right
Click up right
return

F1::Suspend ; F1 hotkey to toggle hotkeys on and off
return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Trying to fix a slight delay that occurs with key bindings

22 Mar 2019, 05:25

The initial pause is caused by key repeat.
Go into notepad, hold any key and observe what happens.
You get one key immediately, followed by a slight pause, then it repeats quite quickly
If you want to get rid of the initial pause, you need to completely rewrite the script and use SetTimer instead

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 88 guests