SendInput while loop gets "stuck"

Get help with using AutoHotkey and its commands and hotkeys
Shrub
Posts: 1
Joined: 16 Feb 2020, 12:04

SendInput while loop gets "stuck"

16 Feb 2020, 12:17

Hi,

So I have an auto-repeatkey macro that spams a key until release.

Here it is (credit to reddit AHK mod for making this):

Code: Select all

; ========== AES ==========
; Only 1 instance of the script can run
#SingleInstance Force
#MaxThreadsPerHotkey 2
; Runs script at full speed
SetBatchLines, -1
; Creates your hotkeys
MakeHotkeys()
; End of AES
;SetBatchLines, -1 

Exit


; ========== Hotkeys ==========
*PgUp::Suspend, Toggle
~*$Tab::SendInput, {Tab}
~*$Space::SendInput, {Space}
~*$F::SendInput, F


; ========== Functions ==========
; Handles all autofire hotkeys
AutoFire(key){
	SendInput, % key
	If GetKeyState(key, "P")
	{
		bf := Func(A_ThisFunc).bind(key)
		SetTimer, % bf, -1
	}
	Return
}

; Dynamically creates all the hotkeys
MakeHotkeys(){
	keyArr := ["r", "b", "v", "q", "c", "t", "e", "x", 1, 2, 3, 4]
	for index, key in keyArr
	{
		bf := Func("AutoFire").bind(key)
		Hotkey, % "*$" key, % bf, On
	}
	Return
}
When using SendInput the key will just get stuck after a while spamming a random key (out of the selection) over and over. It works initially though. This does not occur with SendEvent. Furthermore, this happens when using While loops, or SetTimer (as above), or Loop until GetKeyState. How can I solve this? I wish to use SendInput for the superior speed (given that it's a game macro). I've tried using AHK v2 to the same result, as well as the AutoHotkey_H fork.

Code: Select all

		loop
		{
			SendInput, r
			Sleep, 1
			SendInput, r
		} until !GetKeyState("r", "P")
		return
or

Code: Select all

		while GetKeyState("r","P")
		{
			SendInput, r
			Sleep, 1
			SendInput, r
		}
		return
Thank you all.

Return to “Ask For Help”

Who is online

Users browsing this forum: assak123, Bing [Bot], boiler, joefiesta, malcev, n1ce0n3, poetbox, SilasDeVis, triven, vsub, Weshuggah and 97 guests