On key press help

Ask gaming related questions (AHK v1.1 and older)
warzy
Posts: 9
Joined: 18 Jul 2017, 19:51

On key press help

15 Apr 2018, 01:51

I have a few questions and problems with this code:

1. How do i make it end always on "Send, q{Click}" after i release the key?
2. Any way to make it faster without freezing the computer? Already tried without "Sleep" but didnt success.
3. Sometimes it keeps going after i release the key, realised some times is happening when pressing other keys or clicking while holding the script key also when double tapping it, how could i fix it?
4. Wanted to add more keys with the same function as the "q" one without repeating the same code but not sure how to structure it, also general code optimization tips are welcome.

Thanks in advance!

Code: Select all

#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

<::Suspend
$q::
    While GetKeyState("q","P"){
        Send, q{Click}
        Sleep 1
    } 
return
warzy
Posts: 9
Joined: 18 Jul 2017, 19:51

Re: On key press help

26 Apr 2018, 09:23

Bump
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: On key press help

27 Apr 2018, 10:35

1) If you want to do the same technique more than once, the "GetKeyState Loop" technique is not the way to do it - this is what is causing things to get stuck.
2) You probably DO NOT want to send the keys faster, you want to send them SLOWER.
If you send keys too fast, games will see LESS, not MORE - to the point where if you send keys with no gap between each press and release, games will often see NOTHING.
In practice, you generally need 20-50ms between each down / up event.

Code: Select all

SetKeyDelay, 0, 50 ; Hold each key for 50ms

$q::
	SetTimer, SpamQ, 50
	return

$q up::
	SetTimer, SpamQ, Off
	GoSub, SpamQ	; Press Q one last time as we end
	return

SpamQ:
	Send {q}{click}
	return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 98 guests