Jump to content
LaunchBox Community Forums

Use Platform and Game in AutoHotKey script


YoYo
 Share

Recommended Posts

Ok here is an example of how I do this exact thing using an AHK script for pscx2. I have a set up that determines which game config to use based on the game that is being requested by the front end. In this case, the front end passes full path and rom name. I extract the full path and rom, use AHK function SplitPath which extracts just the romname, then substr to grab the name of the rom without the extension (.iso or such). From there, I am running my own script that knows the rom passed in.  In my case, I then check for whether or not a config with that rom name exists and if so I launch pscx2 with config. Otherwise we use default config.  I call this launchboxstartps2.exe and I told launchbox that pcsx2.exe is actually launchboxstartps2.exe.

Here is my script:


#SingleInstance force      ;Prevent multiple instances
#WinActivateForce          ;Hopefully makes pinball fx window activate.
exitEmulatorKey = Esc 
SetWorkingDir, H:\Game Launcher\Theater\pcsx2

GameName = %1%
SplitPath, GameName, ConfigGame   
ConfigName := SubStr(ConfigGame, 1, -4)

ConfigBase = H:\Game Launcher\Theater\pcsx2\gamesettings
ConfigPath = %ConfigBase%\default

Hotkey, $%exitEmulatorKey%, ClosePcsx2  

ifExist, %ConfigBase%\%ConfigName%
    ConfigPath = %ConfigBase%\%ConfigName%

RunWait, "pcsx2.exe" "%GameName%" --cfgpath="%ConfigPath%" --fullscreen,,UseErrorLevel

ExitApp

ClosePcsx2:
Hotkey, %exitEmulatorKey%, Off
Process, Close, pcsx2.exe

Link to comment
Share on other sites

12 hours ago, markmon said:

Ok here is an example of how I do this exact thing using an AHK script for pscx2. I have a set up that determines which game config to use based on the game that is being requested by the front end. In this case, the front end passes full path and rom name. I extract the full path and rom, use AHK function SplitPath which extracts just the romname, then substr to grab the name of the rom without the extension (.iso or such). From there, I am running my own script that knows the rom passed in.  In my case, I then check for whether or not a config with that rom name exists and if so I launch pscx2 with config. Otherwise we use default config.  I call this launchboxstartps2.exe and I told launchbox that pcsx2.exe is actually launchboxstartps2.exe.

Here is my script:


#SingleInstance force      ;Prevent multiple instances
#WinActivateForce          ;Hopefully makes pinball fx window activate.
exitEmulatorKey = Esc 
SetWorkingDir, H:\Game Launcher\Theater\pcsx2

GameName = %1%
SplitPath, GameName, ConfigGame   
ConfigName := SubStr(ConfigGame, 1, -4)

ConfigBase = H:\Game Launcher\Theater\pcsx2\gamesettings
ConfigPath = %ConfigBase%\default

Hotkey, $%exitEmulatorKey%, ClosePcsx2  

ifExist, %ConfigBase%\%ConfigName%
    ConfigPath = %ConfigBase%\%ConfigName%

RunWait, "pcsx2.exe" "%GameName%" --cfgpath="%ConfigPath%" --fullscreen,,UseErrorLevel

ExitApp

ClosePcsx2:
Hotkey, %exitEmulatorKey%, Off
Process, Close, pcsx2.exe

I completely understand this but how is your LB configured? What command line parameters allow you to read them here?

Link to comment
Share on other sites

You send all command line parameters through the ahk script. Here's my Hoxs64 ahk script - modified with markmon's suggestion so i can read the rom name outside LB - it maps various joystick buttons to Save State, Load State, Wrap on/off, e.t.c and uses the romname to save/load game states.

I compiled the script to .exe and use it as the emu executable instead of hoxs64.exe (so i don't have to setup any ahk scripts or command line parameters in LB)

#SingleInstance force
#WinActivateForce

SetWorkingDir, D:\Emu\C64\hoxs64

GameName = %1%
SplitPath, GameName, rom_name
rom_name := SubStr(rom_name, 1, -4)

RunWait, "hoxs64.exe" -fullscreen -autoload "%GameName%"

; Exit emu
esc::
   Send !{F4}
   ExitApp
Return
4Joy17::
   Send !{F4}
   ExitApp
Return

; Change Disc
4Joy2::
   Send !{enter}
   Sendinput {Alt Down}
   Sendinput {D}
   Sendinput {I}
   Sendinput {E}
   Sendinput {Alt Up}
   WinWait, Choose a disk image file
   WinWaitClose
   Send !{enter}
Return

; Switch Joysticks
4Joy7::
   Send !{j}
Return

; Warp mode On/Off
4Joy15::
   Send !{q}
Return

; Load State
4Joy18::
   IfExist D:\Emu\C64\hoxs64\States\%rom_name%.64s
      Send !{enter}
      Sendinput {Alt Down}
      Sendinput {F}
      Sendinput {Alt Up}
      Send {Down 5}
      Send {Enter}
      WinWait, Load
      Send %rom_name%.64s
      Send {Enter}
      Send !{enter}
Return

; Save State
4Joy19::
   Send !{enter}
   Sendinput {Alt Down}
   Sendinput {F}
   Sendinput {Alt Up}
   Send {Down 6}
   Send {Enter}
   WinWait, Save
   Send %rom_name%
   Send {Enter}
   IfExist D:\Emu\C64\hoxs64\States\%rom_name%.64s
        Send {Alt Down}{Y}{Alt Up}
   Send !{enter}
Return

; Pause
4Joy20::
   Send !{p}
Return

 

 

Edited by Crush
Link to comment
Share on other sites

1 hour ago, Crush said:

You send all command line parameters through the ahk script. Here's my Hoxs64 ahk script - modified with markmon's suggestion so i can read the rom name outside LB - it maps various joystick buttons to Save State, Load State, Wrap on/off, e.t.c and uses the romname to save/load game states.

I compiled the script to .exe and use it as the emu executable instead of hoxs64.exe (so i don't have to setup any ahk scripts or command line parameters in LB)

#SingleInstance force
#WinActivateForce

SetWorkingDir, D:\Emu\C64\hoxs64

GameName = %1%
SplitPath, GameName, rom_name
rom_name := SubStr(rom_name, 1, -4)

RunWait, "hoxs64.exe" -fullscreen -autoload "%GameName%"

; Exit emu
esc::
   Send !{F4}
   ExitApp
Return
4Joy17::
   Send !{F4}
   ExitApp
Return

; Change Disc
4Joy2::
   Send !{enter}
   Sendinput {Alt Down}
   Sendinput {D}
   Sendinput {I}
   Sendinput {E}
   Sendinput {Alt Up}
   WinWait, Choose a disk image file
   WinWaitClose
   Send !{enter}
Return

; Switch Joysticks
4Joy7::
   Send !{j}
Return

; Warp mode On/Off
4Joy15::
   Send !{q}
Return

; Load State
4Joy18::
   IfExist D:\Emu\C64\hoxs64\States\%rom_name%.64s
      Send !{enter}
      Sendinput {Alt Down}
      Sendinput {F}
      Sendinput {Alt Up}
      Send {Down 5}
      Send {Enter}
      WinWait, Load
      Send %rom_name%.64s
      Send {Enter}
      Send !{enter}
Return

; Save State
4Joy19::
   Send !{enter}
   Sendinput {Alt Down}
   Sendinput {F}
   Sendinput {Alt Up}
   Send {Down 6}
   Send {Enter}
   WinWait, Save
   Send %rom_name%
   Send {Enter}
   IfExist D:\Emu\C64\hoxs64\States\%rom_name%.64s
        Send {Alt Down}{Y}{Alt Up}
   Send !{enter}
Return

; Pause
4Joy20::
   Send !{p}
Return

 

 

What dictates what %1% returns? What does %2% return? Is there a %3%? How is markmons script calling %platform%?

Link to comment
Share on other sites

%1% is the first command line parameter, %2% the second, e.t.c

When running a game, LB usually sends the romname (including path) after the emu executable so if you run Archon.g64 with Hoxs64.exe, the command line will be something like:

D:/emu/c64/hoxs64/Hoxs64.exe D:/emu/c64/games/archon.g64

So %1% will hold "D:/emu/c64/games/archon.g64"

Link to comment
Share on other sites

5 hours ago, Crush said:

%1% is the first command line parameter, %2% the second, e.t.c

When running a game, LB usually sends the romname (including path) after the emu executable so if you run Archon.g64 with Hoxs64.exe, the command line will be something like:

D:/emu/c64/hoxs64/Hoxs64.exe D:/emu/c64/games/archon.g64

So %1% will hold "D:/emu/c64/games/archon.g64"

So how would I use the new %gameid% feature?   I added a new exe and left no parameters defined. It output the rom path as %1% but nothing for %2% or %3%. How can I get %platform%, etc. to work?

Link to comment
Share on other sites

  • 1 year later...

Hi, I apologize for bringing this back to life but you guys @ckp @markmon brought something that might help me and in the thread I created no one could.

Stella's games don't open within my LB (nothign happens), but I can right click and "open Stella" to open the emulator and choose the game from the emulator's interface. So, considering that outside of LB the emulator works fine, we all got to the conclusion that there's a problem with the path LB chooses for the emulator. I tried reinstalling, I tried EVERYTHING. What I would like to know is the path commands to confirm our theories. I tried with the msgbox ahk that Mark recommended and got this error (image attached). I tried the batch file that CKP recommended with echo to test.txt but it remains empty. Any idea?

Thank you in advance and I apologize for bothering. Is there any way in which we can follow this elsewhere so I don't bother the rest?

Test Stella.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...