Jump to content
LaunchBox Community Forums

running additional apps with game


Recommended Posts

I ran into a weird problem, hoping someone here can point me in the right direction.

 

Goal:

I'd like to have an app close when I'm finished (exit) a game. The only way I know to do this (I have very limited scripting knowledge) is to make a bat file that closes an app, and run the bat as an additional app in a game's properties in LB. For example: 

image.thumb.png.4307a2edf029b876c504d787794d9650.png

 

Here is what my bat file looks like; it's very simple nothing complex here:

image.png.2c387da8582a1f9bc3c95e3055e56c86.png

 

Issue:

When I launch the game (DirtShowdown in this case), two apps launch: a) antimicro with my controller profile for my racing wheel, and b) the bat that closes antimicro.

The problem is that antimicro is being closed as soon as I launch the game; I need it to wait until the game is closed before running the close bat file. I believe that in order to tell LB to only run the close bat when the game is closed, you have to choose this option:
image.thumb.png.2b5b5450b506bc5fa6d2ad5cdcf73d0b.png

 

This works perfectly for other games that run on emulators, like Retroarch, etc.- but doesn't work with this game which is an exe, not running on an emulator.

 

I've been hitting my head against the wall for hours because this setup worked until now; this is the first time where LB is running applications before/after at the same time, it's almost as if it's ignoring the flag to "Automatically Run After Main Application"- can anyone see what I'm doing wrong? Or maybe someone knows a better way altogether?

 

Also, what is the bottom option for (Wait for Exit)? That sounded like it could be a solution but it's grayed out and you cant select it.

 

Thanks for any help guys!

 

 

 

Link to comment
Share on other sites

Most likely your games exe is a sort of launcher in that it actually [then] launches another application which would be the game.  As soon as the 'launcher' starts the game, it exits itself (and the game plays on).  LaunchBox sees this ('launcher') as the Main Application and in turn runs the After Main Application script (or batch file closing your wheel in this case).

The "Wait for Exit" option is for the Run Before Main App only.

This only explains what's [possibly] going on and doesn't really help.  I'm personally not familiar with DirtShowdown.  Hopefully someone who is, can chime in with actual help.

Link to comment
Share on other sites

Thanks @JoeViking245for chiming in!

 

Yeah I have noticed a pattern; this is only happening with games that launch via their own exe- not happening with games that run on emus (i.e. Retroarch, Pcsx, MAME, etc.)

 

Currently looking for an alternative way of shutting down an app like xpadder, joy to key, antimicro, etc. after a game (exe) closes, but can't find anything so far- a real mind bender!

Link to comment
Share on other sites

12 hours ago, BabyBillyFreeman said:

Thanks @JoeViking245for chiming in!

 

Yeah I have noticed a pattern; this is only happening with games that launch via their own exe- not happening with games that run on emus (i.e. Retroarch, Pcsx, MAME, etc.)

 

Currently looking for an alternative way of shutting down an app like xpadder, joy to key, antimicro, etc. after a game (exe) closes, but can't find anything so far- a real mind bender!

 

This is easy to accomplish if I understand your goal right. If I were you I would make an AHK script file and insert this new AHK script file as an additional application to be launched along with the game Dirt Showdown. I'd have it ticked to run prior to launching the main application also. It will wait to detect that the game has shut down, and at that point, it will close the antimicro application. ExitApp makes the script terminate once it's done everything you wanted it to.

 

If you have AHK installed you're all set. If you don't that's also OK, it's not necessary. If you don't have it installed simply make the .ahk file extension associated with opening with the AHK executable included with LaunchBox/BigBox. It is in the LaunchBox/ThirdParty/AutoHotKey folder. That way you can point the additional app to launch the AHK script directly. Alternatively you could also point to the AHK executable in the LaunchBox/ThirdParty/AutoHotKey folder and in the parameters field add the file path to the AHK script so it will run that script. Both methods result in the same outcome


 

WinWaitClose, ahk_exe dirtshowdown.exe
WinClose, ahk_exe antimicro.exe
ExitApp

 

Not knowing exactly what antimicro is, if this WinClose command doesn't work to close it, replace that entire line "WinClose, ahk_exe antimicro.exe" with "Process, Close, antimicro.exe"  so like this.
 

WinWaitClose, ahk_exe dirtshowdown.exe
Process, Close, antimicro.exe
ExitApp

 

Link to comment
Share on other sites

  • 2 months later...

Hey @skizzosjt sorry i didn't respond earlier, got super busy with work and only now coming back to this.

 

I'm trying this technique (thanks for the great suggestion BTW!) on a steam game called Door Kickers and I'm using Joy To Key for button mapping (gamepad to keyboard).

I used the following AHK script which I saved as a .ahk file (uses the ahk.exe that comes with LB)
WinWaitClose, ahk_exe DoorKickers.exe
WinClose, ahk_exe JoyToKey.exe
ExitApp

However, it doesn't seem to have any effect at all whether I run it manually or with LB additional apps
image.thumb.png.8ed945ee3529792e2b0cba31885a5df9.png

I also tried the following script, but same result:

WinWaitClose, ahk_exe DoorKickers.exe
Process, Close, JoyToKey.exe
ExitApp

I'm still learning so I'm positive I'm doing something wrong that is probably super obvious to more experienced folks haha

If anyone has any pointers, it'd be very much appreciated!

Link to comment
Share on other sites

Hi @BabyBillyFreeman I like the script name lol. I have joytokey, but beyond some initial testing and farting around with it, I never used it in a practical setup. So I'm not sure if there are any nuances to closing it via a script. When you say no effect, does this mean that JoyToKey is never closed, and is always still running when you exit DoorKickers? or is JoyToKey closing too soon and therefore your button remapping doesn't work while playing DoorKickers?

I would go at it with some basic tests. Try something like this.

WinWait, ahk_exe DoorKickers.exe
SoundBeep
WinWaitClose, ahk_exe DoorKickers.exe
SoundBeep

If you never hear any beeps, or if you hear both beeps right away upon starting the game rather than the 2nd one when you're done and exit the game, then the script isn't working as expected. You should hear one when the game starts, and one when you exit, that would mean the script is detecting your games process OK.

After reading my previous advice, I should have suggested using WinWait also because what could be happening is the script runs before the game's process exists, so therefore the WinWaitClose line thinks "process is closed since it doesn't exist" and then would terminate JoyToKey much earlier, basically at boot of the game.

If you never hear a beep, this suggests it's not detecting things right for the "WinTitle" used. If that is the case, I would ask you double check that the exe name is typed out correctly.  It's not case sensitive when using the ahk_exe title but is important that the characters match exactly otherwise. 

Joe has good advice as usual too. Since you mentioned it's a Steam game and what he mentioned is games that have a launcher then launch the game, like most Steam games, tend to have the ability to mess up how a script behaves, usually terminating them prematurely. I'm also now maybe connecting the dots to your comment about this happens only with games that launch via an exe.....likely all Steam games or at least ones that have a launcher perhaps. So the stuff I suggested this time around should prove whether or not if this is happening to you. So take note of when you hear those beeps, and also take note of if/when the script gets closed if it's being terminated early.

  • Like 1
Link to comment
Share on other sites

On 10/9/2022 at 7:22 PM, BabyBillyFreeman said:

a steam game called Door Kickers

With a Steam game, what's happening is as I described above.  When you launch the via "steam://rungameid/248610", it opens steam THEN opens DoorKickers.exe.

Also, what's happening with your script is it's ran BEFORE the main application (which is what you want) and the 1st thing it does is wait for DoorKickers to get closed (exited).  Since at this point DoorKickers isn't even running, the script "is done waiting" and goes to the next line.  Which is to shutdown/exit joytokey.  

You say "it doesn't seem to have any effect".  Is it not even closing joytokey?  Do you have a 2nd additional app (also set to run BEFORE) that's starting joy2key?  I suppose you'd kind of have to.  So, these 2 scripts [at this point] are butting heads.  Easy fix, combine the 2 scripts.

You'll want to (NEED to) add in a WinWait to wait for DoorKickers.exe to actually be running. THEN you can wait for it to close.

Run, "D:\Utilities\JoyToKey\JoyToKey.exe"
WinWait, ahk_exe DoorKickers.exe
WinWaitClose
;WinClose, ahk_exe JoyToKey.exe  **DOES NOT WORK WITH JoyToKey.exe**
Process, Close, JoyToKey.exe

The issue doing it this way is you need to create a different script for each game.  Replacing DoorKickers.exe with the 'new' games [actual] executable.  Which, beyond being tedious, isn't that big of a deal.

EDIT:  I am told (I've never used it myself) JoyToKey.exe is one of the few programs that require "extra force" when closing.  WinClose will not work.  You need to use:

Process, Close, JoyToKey.exe

Codes has been edited to reflect this change.

Another option is to create a new "emulator" which is actually an AutoHotkey script used to launch your Steam games.  It's a onetime setup and will work for all your Steam games that are launched via "steam://rungameid/xxxxxx".

The script would look something like this:

Run, "D:\Utilities\JoyToKey\JoyToKey.exe"                       ;**** Verify Path ****
Run, "C:\Program Files (x86)\Steam\Steam.exe" -applaunch %1%    ;**** Verify Path ****

isRunning := "0"
While (isRunning = "0") ; Wait until the game is launched
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

While (isRunning = "1") ; Wait until the game is closed
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

Process, Close, JoyToKey.exe

 

In LaunchBox add a new emulator.  Use (Browse.. to) AutoHotkey.exe that comes with LaunchBox as your Application Path, so you don't have to install it. (LaunchBox will convert it to a Relative Path, as shown.)  Point to the script as your Default Command Line. ("Put this path in quotes.)  Check BOTH boxes. Save. 

image.thumb.png.cafd0f68d5ddd676bbb64f1511ed5649.png

 

Set the Steam games you want to use JoyToKey with to use this emulator.

image.thumb.png.e7a0aab2c4ab54c2de0eab4d302bc10b.png

 

If you want all your Steam games to use JoyToKey, when creating the "emulator", go to the Associated Platforms section, select "Windows" (or whatever you've named the Platform, default is "Windows") under Associated Platforms and check the box Default Emulator.  Skip the above Edit Game all together.

Edited by JoeViking245
Changed "WinClose" to "Process, Close"
Link to comment
Share on other sites

Hey @JoeViking245 so maybe I've forgotten how many hoops I've jumped through to get this or that working, but this kinda stuff (additional apps) I don't remember having to mess around with like this. I figured I was remembering wrong bc I too use script launching methods which would bypass the Steam launching problems mentioned but I edited a handful of games to remove emulation (turned it off) so it would return to the normal "steam://rungameid/[insertID#here]" method. When I attached a script as an additional app it works as intended. So if I can launch additional apps on Steam games without the extra setup I'm under the impression others can do so without the additional steps. I much like the script launching method and I've never seen the registry method you shared, that's a really neat way of implementing it! But it's what I would call the scenic route, it totally works, just takes a little longer to get there is all. If I'm having luck achieving this and yourself or others share none of what I'm detailing works, then I just don't know what setting or some special config I made that is allowing it to work for me (I'd have to investigate further), but I wanted to share it does in fact work for me in this setup. That being as long as the script is an additional app it should behave OK. If the script was put in the catch all "Tools > Manage > Scripts > Edit AHK scripts for Windows games" then it would behave as you described for me, always prematurely terminating within what seems like a fraction of second of at launch of Steam games. Additionally thanks for sharing JoyToKey needs a little extra kick in the pants to do what it's told with Process, Close

  • Like 1
Link to comment
Share on other sites

12 hours ago, skizzosjt said:

So if I can launch additional apps on Steam games without the extra setup I'm under the impression others can do so without the additional steps.

I think "extra setup" is the key phrase here.

(To iterate, what we're trying to accomplish here is to run (close, actually) an application After running/playing a Steam game that is loaded via its ID#.)

Using the Additional App script technique works for you and will work for me and everyone else as well.  Unchecking "Use an emulator..." and having the game point to "steam://rungameid/######".  The key that makes it work is the WinWait line in the script.  Plus, of course, having the Additional App checked to run Before the Main Application.  However, that one script will only work for that one game because you have to tell WinWait specifically what to wait for. 

This is where the "extra setup" comes into play.  You have to create a script specific to each game.  But that's easy... copy the 1st script and change the game_name.exe on the WinWait line.  Well, after you find out what the exe name is.  Save the new (2nd) script then add an Additional App to your 2nd Steam game using this [2nd] saved script.  Now do this for the rest of your Steams games that need to use JoyToKey.  If you have 25 Steam games needing j2k, you now only have to do this 23 more times.  If you only have 3 or 4 games that require J2K, this is the way to go.  But I assume if [for whatever reason] you need to use JoyToKey for some Steams games, you need to use it for all.  

 

This is where (I feel) the "scenic route" is pretty, in nature. (pun intended :D). *

  • Create one script.
  • Create one new emulator.
  • Set it as the Default Emulator for your Steam games Platform. 

If only certain games require J2K, then the process will become a little more scenic.   Don't set it as the Default Emulator. While holding Ctrl, click the games that require J2K.  Click Edit to start the Bulk Edit Wizard. Set 'emulator' to the one-script emulator you created.

 

Ideally, you'd not have to use J2K at all.  Again, I don't use it myself and don't know the circumstances that it's required.

 

*I'm not saying my 'emulator script' is pretty, by any means.  If fact it can probably be considered a Hack.  Which by definition, is ugly in itself. lol  But it is one way to accomplish our desired goal. ;)  The per-game script is another.  And setting the games to launch directly to the exe is yet another. But not ideal.

  • Like 1
Link to comment
Share on other sites

2 hours ago, JoeViking245 said:

The key that makes it work is the WinWait line in the script

great point Joe! I didn't consider this part in my previous response. I was under the impression at that moment it was just a single game and was thinking why go through the extra setup when you can make a single script and call it day. Declaring the single game as the WinTitle for the WinWait line is no problem there. However now considering they did make the point the problem occurs for all Steam games, as expected, perhaps they need to use aux programs for multiple games and in that case, going down the path of setting up games being launched via a script to use a variable pulling in the ID# now makes sense to me. I think the script is hands down the most interesting way I've seen this tactic implemented! Call it whatever you want, I think it's cool in all its nerdy glory! I just didn't follow why you were leading them down the scenic route when I was thinking you went right past the shortcut route lol. But now I'm on the same page!

  • Haha 1
Link to comment
Share on other sites

  • 1 year later...

I'm not an expert, but I'll give it a shot. It seems like you need to find a way for your ""close bat"" to wait until the game is done. One thing that comes to mind is creating a batch script that runs continuously in the background, checking for when the game process is no longer running. Then, when it detects that the game has closed, it can execute the close action for antimicro.I hope this makes sense and points you in the right direction. Don't be discouraged by your limited scripting knowledge; we all start somewhere! And who knows, you might even find it fun to tinker with scripts and learn more along the way.And if you're looking for ways to make some extra cash with apps, you might want to check out some apps that pay you real money. They can be a great addition to your gaming setup!

Edited by TobyRooney
  • Thanks 1
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...