TAS Engine

Ask gaming related questions (AHK v1.1 and older)
DoraChad
Posts: 3
Joined: 01 Mar 2024, 22:37

TAS Engine

Post by DoraChad » 01 Mar 2024, 22:47

I am trying to make a program which runs given commands to essentially make a TAS tool, but the program has problems.
1. The program that I am trying to send the inputs to runs at 60 fps (a racing game), so depending on when I start the program, the output will be different in the game. I assume this is because of lag and also because my input system uses the sleep command, which runs in milliseconds (100 fps). This means that depending on when I start the script the time that the inputs are executed will change.
2. There is a couple frames of no input when the code is decoding the script to figure out what next to input, and I'm sure this could be fixed with some optimizations in the code.

Here is the code:

Code: Select all

#SingleInstance, Force
Setbatchlines -1


linenum := 1
FileReadLine, text, Inputs.txt, linenum

outputs := StrSplit(text, ":")
Keys := outputs[1]
extime := outputs[2]

Loop
{
	if (GetKeyState("P") = 1)
		break

}




Loop
{
	Sleep extime
	
	SendKeys := StrSplit(Keys, ",")
	K1 := SendKeys[1]
	K2 := SendKeys[2]
	K3 := SendKeys[3]
	K4 := SendKeys[4]
	
	Send,{W Up}
	Send,{A Up}
	Send,{S Up}
	Send,{D Up}
	Send,{%K1% Down}
	Send,{%K2% Down}
	Send,{%K3% Down}
	Send,{%K4% Down}
			

	linenum += 1
	FileReadLine, text, Inputs.txt, linenum
	outputs := StrSplit(text, ":")
	Keys := outputs[1]
	extime := outputs[2]
	if (extime = 0000)
		break

	sleep, 1
}



ESC::ExitApp


The input file looks something like this:

W,A:1000
W:120
W,D:4600
W:200
S,D:1600
W:1600
W,D:2700
S,D:2500
W:1900


As you can see above, the inputs that the script is supposed to perform is written before the colon and each letter of input is separated by a comma. After the colon, there is the amount of time that the script should wait before executing the given input (This is all in the script at the top).

Does anyone have any suggestions on how to fix my problems?

[Mod edit: Replaced the bold tags with [code][/code] tags. Please use them yourself when posting code. Also removed extra blank lines in post.]

[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code and to the "Gaming" section within that.]

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: TAS Engine

Post by mikeyww » 02 Mar 2024, 05:29

Welcome to this AutoHotkey forum!

Ideas are below. If you wanted the subroutine to send keys immediately, you would sleep after the key is sent instead of beforehand. A feature of AutoHotkey is the hotkeys! This allows you to trigger a subroutine by pressing a key. Send lowercase letters unless you need uppercase ones. AHK will manage Shift accordingly. See the KeyHistory to understand what is happening with your keys.

Code: Select all

#Requires AutoHotkey v1.1.33.11
inputs := "inputs.txt"
arr    := [] ; Array will contain arrays of the values for [sendKeys, sleepTime]
If FileExist(inputs) {
 FileRead txt, % inputs
 For each, line in StrSplit(txt, "`n")           ; Loop through lines in text file
  arr.Push(StrSplit(line, ":"))                  ; Store the new [sendKeys, sleepTime]
 SoundBeep 1500
} Else MsgBox 48, Error, % "File not found.`n`n" inputs

p::
SetBatchLines -1
For n, part in arr {                             ; Loop through the array; part is [sendKeys, sleepTime]
 ToolTip % n
 Sleep part[2]                                   ; The sleepTime
 Gosub Reset
 Loop Parse, % part[1]                           ; Loop through the sendKeys in this array
  SendInput % Format("{{:L} down}", A_LoopField) ; Send down the lowercase letter
}
ToolTip
SoundBeep 1000
Reset:
SendInput {w up}{a up}{s up}{d up}
Return
Inputs:

Code: Select all

wa:1000
w:120
wd:4600
w:200
sd:1600
w:1600
wd:2700
wd:2500
w:1900

DoraChad
Posts: 3
Joined: 01 Mar 2024, 22:37

Re: TAS Engine

Post by DoraChad » 02 Mar 2024, 12:29

@mikeyww
Thanks!!
This resolves the lag problem and shortens the script nicely.
Do you have any ideas on how to fix the other problem (inconsistent inputs when playing the inputs to a 60fps racing game)?

DoraChad
Posts: 3
Joined: 01 Mar 2024, 22:37

Re: TAS Engine

Post by DoraChad » 02 Mar 2024, 12:47

@mikeyww
Do you know how I could make a keylogger which incodes the inputs instead of executes them?
The code I wrote also lags to much and isn't fast enough to catch fast inputs.

User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: TAS Engine

Post by boiler » 02 Mar 2024, 14:33

We don't discuss creating keyloggers on this forum, no matter the purpose. Please refrain from asking about this again. Thank you.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: TAS Engine

Post by mikeyww » 02 Mar 2024, 14:39

Regarding the inputs, I have no insight into that, but examining the :arrow: KeyHistory will help you to understand the keys and their timing.

Post Reply

Return to “Gaming Help (v1)”