First post, by Stretch
Any ideas why this AutoIT script works properly with Dosbox and Doom2, but not Duke3d?
The script simulates keyboard presses, which I am using to record FM OPL to DRO files.
If I modify the script for Duke3d, ingame none of the keypresses register.
I tried Duke3d with Dos4/GW and Dos32a.
AutoIT script
#include <MsgBoxConstants.au3>
Global $dosboxPath = "C:\Program Files (x86)\DOSBox-0.74\DOSBox.exe"
; doom2.conf runs a batch file called d2vgm.bat
Global $dosboxConfig = "C:\temp\doom2.conf"
; Length of each level in seconds
Global $audioTrackLength = "C:\temp\audioTrackLength.txt"
; Exit if required files not found
Global $fName
CheckDependency($dosboxPath)
CheckDependency($dosboxConfig)
CheckDependency($audioTrackLength)
; Run Dosbox
Run('"' & $dosboxPath & '"' & ' -conf ' & '"' & $dosboxConfig & '"')
; Wait 3 seconds for Dosbox to load
Global $hWnd = WinWait("[CLASS:Dosbox]", "", 3)
Sleep(3000)
; The main part of the script
ReadTextFile()
; Quit if required files are not found
; https://www.autoitscript.com/autoit3/docs/functions/FileExists.htm
Func CheckDependency($fName)
Local $iFileExists = FileExists($fName)
If Not $iFileExists Then
MsgBox($MB_SYSTEMMODAL, "", "The file " & $fName & " doesn't exist." & @CRLF & "FileExist returned: " & $iFileExists)
Exit 1
EndIf
EndFunc
; https://www.autoitscript.com/forum/topic/111408-read-text-file-line-by-line/
; Script from user MHz
Func ReadTextFile()
; open file to read and store the handle
$handle_read = FileOpen($audioTrackLength, 0)
; check the handle is valid
If $handle_read = -1 Then
; show warning and exit with code 1
MsgBox(0, @ScriptName, 'failed to open handle to read the file')
Exit 1
EndIf
; loop through each line of the file
While 1
; read each line from a file
$line_read = FileReadLine($handle_read)
; exit the loop if end of file
If @error Then ExitLoop
; Add 5 seconds
; And multiply by 1000 for Sleep function
If $line_read > 1 Then
Local $strTrackLength = Number(($line_read + 5) * 1000)
Else
ContinueLoop
EndIf
; Activate the Dosbox window using the handle returned by WinWait.
WinActivate($hWnd)
Sleep(200)
; Begin VGM Recording
Send("^!{F7}")
Sleep(2000)
; Exit pause command in batch file
Send("ENTER")
; Wait for level to load
Sleep(8000)
; God mode idkfa
; change to dnkroz for duke3d
Send("idkfa")
; Sleep for the length of the track read from file
Sleep($strTrackLength)
; Exit Doom - Escape, Up, Enter, y
Send("{ESCAPE}")
Sleep(1000)
Send("{UP}")
Sleep(1000)
Send("{ENTER}")
Sleep(1000)
Send("y")
; Uncomment for Duke3d
; Sleep(2000);
; Send("{ENTER}")
; Wait for game to exit to command prompt
Sleep(4000)
; End VGM Recording
Send("^!{F7}")
Sleep(2000)
WEnd
; close the file handle for read
FileClose($handle_read)
EndFunc
d2vgm.bat
@echo off
REM For WAD games like Doom and Doom2
SET DMXOPTION=-opl3-phase
REM DOOM.exe -opl3 -phase -warp 1 1 -nomonsters -nosfx
REM DOOM2.EXE -opl3 -phase -warp 01 -nomonsters -nosfx
REM duke3d.exe /m /ns /v1 /l1
pause
DOOM2.EXE -opl3 -phase -warp 01 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 02 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 03 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 04 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 05 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 06 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 07 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 08 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 09 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 10 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 18 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 20 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 23 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 25 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 28 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 30 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 31 -nomonsters -nosfx
pause
DOOM2.EXE -opl3 -phase -warp 32 -nomonsters -nosfx
REM FreeDOS sleep
sleep.exe 5
exit
AudioTrackLength.txt doom2
230
292
230
155
259
417
257
300
279
263
306
279
99
115
282
279
72
79
d3dvgm.bat
@echo off
pause
duke3d.exe /m /ns /v1 /l1
pause
duke3d.exe /m /ns /v1 /l2
pause
duke3d.exe /m /ns /v1 /l3
pause
duke3d.exe /m /ns /v1 /l4
pause
duke3d.exe /m /ns /v1 /l5
pause
duke3d.exe /m /ns /v1 /l6
pause
duke3d.exe /m /ns /v1 /l7
pause
duke3d.exe /m /ns /v2 /l1
pause
duke3d.exe /m /ns /v2 /l2
pause
duke3d.exe /m /ns /v2 /l3
pause
duke3d.exe /m /ns /v2 /l4
pause
duke3d.exe /m /ns /v2 /l5
pause
duke3d.exe /m /ns /v2 /l6
pause
duke3d.exe /m /ns /v2 /l7
pause
duke3d.exe /m /ns /v2 /l8
pause
duke3d.exe /m /ns /v2 /l9
pause
duke3d.exe /m /ns /v2 /l10
pause
duke3d.exe /m /ns /v2 /l11
pause
duke3d.exe /m /ns /v3 /l1
pause
duke3d.exe /m /ns /v3 /l2
pause
duke3d.exe /m /ns /v3 /l3
pause
duke3d.exe /m /ns /v3 /l4
pause
duke3d.exe /m /ns /v3 /l5
pause
duke3d.exe /m /ns /v3 /l6
pause
duke3d.exe /m /ns /v3 /l7
pause
duke3d.exe /m /ns /v3 /l8
pause
duke3d.exe /m /ns /v3 /l9
pause
duke3d.exe /m /ns /v3 /l10
pause
duke3d.exe /m /ns /v3 /l11
pause
duke3d.exe /m /ns /v4 /l1
pause
duke3d.exe /m /ns /v4 /l2
pause
duke3d.exe /m /ns /v4 /l3
pause
duke3d.exe /m /ns /v4 /l4
pause
duke3d.exe /m /ns /v4 /l5
pause
duke3d.exe /m /ns /v4 /l6
pause
duke3d.exe /m /ns /v4 /l7
pause
duke3d.exe /m /ns /v4 /l8
pause
duke3d.exe /m /ns /v4 /l9
pause
duke3d.exe /m /ns /v4 /l10
pause
duke3d.exe /m /ns /v4 /l11
sleep.exe 5
exit
audiotracklength.txt duke3d
164
242
359
353
353
376
103
201
315
232
146
185
311
195
147
184
153
165
246
254
334
394
289
158
401
379
161
251
220
179
190
130
217
185
212
213
193
281
200
172
Win 11 - Intel i7-1360p - 32 GB - Intel Iris Xe - Sound BlasterX G5