SetKeyDelay problem in DS3 autofarm script

Ask gaming related questions
JaydeNpie
Posts: 15
Joined: 04 Jan 2019, 04:13

SetKeyDelay problem in DS3 autofarm script

Post by JaydeNpie » 22 Jul 2019, 17:21

I am making an autofarm script for DS3, and it involves pressing f twice with a delay between. The problem is that f can not be held for longer that 500ms, which usually isnt a problem using SetKeyDelay. But for some reason, a certain f press seems to be held for longer than SetKeyDelay says. Ive tried changing SetKeyDelay, specifying SendEvent {f}, and all other SendModess. Ive set KeyDelay to 0, which resulted in the key not registering in game, which was expected. This tells me that it IS reading the KeyDelay, but even set at 50, it holds longer than 500ms. The code is below (I wrote the majority of then when I was still relatively new to AHK, so please do tell me any optimizations). I added the Numpad 4 hotkey to test if it was just how it was, but it works perfectly fine, and doesnt "stick" when isolated like that.

Code: Select all

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

#NoEnv
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SetKeyDelay,, 250
global lightColX := 0
global lightColY := 0
global keepLooping := 0
global fpFine := 0
global setHPx := 0
global setHPy := 0
global setFPx := 0
global setFPy := 0
global ashenUsed := 0
global BlueA := 0
global BlueB := 0
global BlueC := 0
global BlueD := 0
checkBars(){
	PixelGetColor, hpColor, %setHPx%, %setHPy%, RGB
	if !(hpColor = hpFine){
		sleep, 250
		Send r
		sleep, 1000
		}
	PixelGetColor, fpColor, %setFPx%, %setFPy%, RGB
	if !(fpColor = fpFine){
		sleep, 250
		SetKeyDelay,, 100
		Send {Down}
		sleep, 100
		SetKeyDelay,, 500
		Send r
		sleep, 200
		Send {Down}
		sleep, 100
		ashenUsed += 1
		}
	return
	}
Numpad0::keepLooping := 0

Numpad1::setBars()

setBars(){
	CoordMode, Mouse, Screen
	ToolTip, Right Click to set HP Bar spot.`nDo not move mouse after Right Click.
	Keywait, RButton, D
	MouseGetPos, setHPx, setHPy
	sleep, 250
	ToolTip, HP Bar set.
	ToolTip, Right Click again to set FP Bar spot.`nDo not move mouse after Right Click.
	Keywait, RButton, D
	MouseGetPos, setFPx, setFPy
	sleep, 250
	ToolTip, FP Bar set.
	sleep, 3000
	ToolTip,  
	}
	
Numpad9::frfr()

frfr(){
	keepLooping := 1
	CoordMode, Pixel, Screen
	PixelGetColor, hpFine, %setHPx%, %setHPy%, RGB
	PixelGetColor, fpFine, %setFPx%, %setFPy%, RGB
	while (keepLooping = 1){
		Send {Space down}
		sleep, 250
		Send {w down}
		sleep, 3900
		Send {w up}
		sleep, 250
		Send {m down}
		sleep, 1000
		Send {m up}
		}
	}
	
Numpad2::lllll()

lllll(){
	CoordMode, Pixel, Screen
	keepLooping := 1
	Send {Space down}
	Send {w down}
	sleep, 4300
	Send {Space up}
	Send {w up}
	sleep, 250
	Loop 
		{
		SendMode Event
		Send {LCtrl}
		sleep, 750
		if (keepLooping = 0){
			break
			}
		Send {m down}
		sleep, 850
		if (keepLooping = 0){
			break
			}
		Send {m up}
		sleep, 350
		if (keepLooping = 0){
			break
			}
		Send q
		sleep, 35
		Send {a down}
		sleep, 375
		Send {a up}
		if (keepLooping = 0){
			break
			}
		sleep, 1000
		Send {w down}
		sleep, 500
		Send {w up}
		if (keepLooping = 0){
			break
			}
		sleep, 5000
		Click, down, L
		sleep, 250
		Click, up, L
		sleep, 3500
		if (keepLooping = 0){
			break
			}
		Send {w down}
		sleep, 650
		Send {w up}
		if (keepLooping = 0){
			break
			}
		Send {RCtrl down}
		sleep, 2000
		Send {RCtrl up}
		if (keepLooping = 0){
			break
			}
		sleep, 1750
		Send f
		if (keepLooping = 0){
			break
			}
		sleep, 250
		Click, down, R
		sleep, 30
		Send {m down}
		sleep, 750
		leftDone := 0
		lightColX := 890
		lightColY := 386
		Send {m up}
		sleep, 175
		Send {m down}
		Loop
			{
			hexadecFinder()
			if (BlueA > 175){
				Send {m up}
				Send {n up}
				Click, up, R
				sleep, 250
				leftDone := 0
				Send {w down}
				sleep, 2250
				Send {w up}
				sleep, 150
				SetKeyDelay,, 25
				Send f ;Not sure if this one is doing it too, as it doesnt make a difference here.
				sleep, 50
				Send f ;THIS ONE RIGHT HERE <--- Even with redefining KeyDelay, still gets held too long(?)
				SetKeyDelay,, 250
				break
				}
			if (keepLooping = 0){
				Send {m up}
				Send {n up}
				break 2
				}
			}
		}
	}

Numpad4::
Send f ;This works perfectly fine, but the one above is somehow "sticking" when sent.
sleep, 250
Send f

hexadecFinder(){
	CoordMode, Pixel, Screen
	PixelGetColor, color0, 890, 386
	BlueA:="0x" SubStr(color0,3,2) ;substr is to get the piece
	BlueA:=BlueA+0 ;add 0 is to convert it to the current number format
	return
	}
	
;	PixelGetColor, color, 800, 481
;	Blue:="0x" SubStr(color,3,2) ;substr is to get the piece
;	Blue:=Blue+0 ;add 0 is to convert it to the current number format
;	Green:="0x" SubStr(color,5,2)
;	Green:=Green+0
;	Red:="0x" SubStr(color,7,2)
;	Red:=Red+0
[Mod edit: Topic name added]

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

Re: SetKeyDelay problem in DS3 autofarm script

Post by evilC » 23 Jul 2019, 05:46

It's quite a lot of code, not really analysed it much, but there appears to be a lot of loops in hotkeys.
Are you expecting any of these loops to be running at the same time? Cos that won't work and may exhibit odd behaviour such as "stuck" keys.

If you want a robust way to perform ongoing repeated sequence of keys, with the option to break out at any point, see SequenceSender

Post Reply

Return to “Gaming”