Jump to content
LaunchBox Community Forums

need help with launching and closing an application when rom loads


sirgubster9

Recommended Posts

I am trying to use this app called keyboard2xinput I can in theory have it load easily using the section available on launchbox, but I need it to close after i close that rom. the only way I can normally close it is by going down to the taskbar right clicking on it and pressing exit.  I posted this question on the forum for that software and I recieved this info and i thought since you guys know more abotu programming and more about launchbox you could instruct me how to do this:

Setup Launchbox to point to custom AHK script instead of games exe.

This is example of one of my AHK:
 

Code: [Select]

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force
#Persistent

Run D:\Games\Keyboard2Xinput\Keyboard2XinputGui.exe
Sleep, 1000  ; sleep 1 second
Run D:\Games\Game shortcuts\DoubleDragon.exe.lnk
Sleep, 1000  ; sleep 1 second

proc1 = DoubleDragon.exe
Process, Wait, %proc1%
Process, WaitClose, %proc1%
SendInput {NumpadMult}
ExitApp

Once windows process DoubleDragon ends AHK sends * NumpadMult which closes Keyboard2Xinput

Edited by sirgubster9
Link to comment
Share on other sites

2 hours ago, sirgubster9 said:

the only way I can normally close it is by going down to the taskbar right clicking on it and pressing exit. 

According to the script, you can press the asterisk ( * ) on the number pad to close keyboard2xinput.  Can you 1st verify that pressing that key does indeed work for you?  If it doesn't, setting up this script won't do any good.  Just sayin'. ;) 

 

And if it does work, setup LaunchBox to point to custom AHK script instead of the games exe.  To do this:

  1. Create a new text file and save it to somewhere you won't forget nor accidentally delete.  Say somewhere like "D:\Games\Double Dragon\"    
  2. Inside that text file, copy and paste the code you found above.
    • Be sure that the paths on the TWO separate lines that start with Run are pointing to the correct paths and files for your app and game.
  3. Save the file, but save it with an "ahk" file extension.  I.e. "MyDoubleDragon.ahk".  (make sure it doesn't save as "MyDoubleDragon.ahk.txt")
  4. In LaunchBox, Edit your Double Dragon game
  5. Go to the Launching section.
  6. Where it says Application Path: click Browse and navigate to and select  ../LaunchBox/ThirdParty/AutoHotkey/AutoHotkey.exe
  7. Where it says Application Command-Line Parameters:, type in the full path to where you saved the file you created above. And put quotes around it.    
    • i.e.  "D:\Games\Double Dragon\MyDoubleDragon.ahk"
  8. Click OK to save and close.
  9. Play Double Dragon.
     
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, JoeViking245 said:

According to the script, you can press the asterisk ( * ) on the number pad to close keyboard2xinput.  Can you 1st verify that pressing that key does indeed work for you?  If it doesn't, setting up this script won't do any good.  Just sayin'. ;) 

 

And if it does work, setup LaunchBox to point to custom AHK script instead of the games exe.  To do this:

  1. Create a new text file and save it to somewhere you won't forget nor accidentally delete.  Say somewhere like "D:\Games\Double Dragon\"    
  2. Inside that text file, copy and paste the code you found above.
    • Be sure that the paths on the TWO separate lines that start with Run are pointing to the correct paths and files for your app and game.
  3. Save the file, but save it with an "ahk" file extension.  I.e. "MyDoubleDragon.ahk".  (make sure it doesn't save as "MyDoubleDragon.ahk.txt")
  4. In LaunchBox, Edit your Double Dragon game
  5. Go to the Launching section.
  6. Where it says Application Path: click Browse and navigate to and select  ../LaunchBox/ThirdParty/AutoHotkey/AutoHotkey.exe
  7. Where it says Application Command-Line Parameters:, type in the full path to where you saved the file you created above. And put quotes around it.    
    • i.e.  "D:\Games\Double Dragon\MyDoubleDragon.ahk"
  8. Click OK to save and close.
  9. Play Double Dragon.
     

you are a genius and a saint.  everything worked perfectly..... almost.  Only issue is whenever i run the game on launchbox everything goes according to plan except it gets an error after its been open for say 10 seconds and has to close down?  When I run it without launchbox no problems and when i run it through launchbox but not as a AHK no problems so im assuming something to do with that code is causing an issue, any ideas?

Link to comment
Share on other sites

Glad to help!

Are you Running the games exe file? Or are you using a shortcut to the exe (like the script is indicating)?  Any reason not to use the exe directly?

If you can run 'DoubleDragon.exe' directly, try something like:

Run, D:\Games\Keyboard2Xinput\Keyboard2XinputGui.exe
Sleep, 1000  ; sleep 1 second
RunWait, D:\Games\DoubleDragon.exe
SendInput, {NumpadMult}

"RunWait" will start DoubleDragon.exe and hang around until it's no longer running. When it's not running anymore, then, and only then will it press the asterisk key. The script will then exit itself.

You don't need all the other stuff in the script.  Oh, again... make sure the path to the exe(s) is (are) correct.

Link to comment
Share on other sites

17 hours ago, JoeViking245 said:

Glad to help!

Are you Running the games exe file? Or are you using a shortcut to the exe (like the script is indicating)?  Any reason not to use the exe directly?

If you can run 'DoubleDragon.exe' directly, try something like:

Run, D:\Games\Keyboard2Xinput\Keyboard2XinputGui.exe
Sleep, 1000  ; sleep 1 second
RunWait, D:\Games\DoubleDragon.exe
SendInput, {NumpadMult}

"RunWait" will start DoubleDragon.exe and hang around until it's no longer running. When it's not running anymore, then, and only then will it press the asterisk key. The script will then exit itself.

You don't need all the other stuff in the script.  Oh, again... make sure the path to the exe(s) is (are) correct.

I am running the exe and not the shortcut, dont know why his code was using a shortcut but I changed that. 

I tried using your code exactly and just got rid of everything else and sadly same results. Well not exactly I obviously pointed it to my stuff.  But ya still same issue of error and game closing. 

oh new idea that you can probably help me with.  what if I run the game exe using launchbox normally and then i have additional apps run the other keyboardinput app.  and now that I know asterix closes the app is there anyway to have the esc button be esc plus asterix?  is there a macro or something that would allow me to do that?

Link to comment
Share on other sites

1 hour ago, sirgubster9 said:

But ya still same issue of error and game closing.

What exactly is the error saying?  Can you take a screenshot of it?

 

1 hour ago, sirgubster9 said:

what if I run the game exe using launchbox normally and then i have additional apps run the other keyboardinput app. 

Sure.

Step 1:

Start by adding (or editing) the game. Go to the Launching section and Browse to your DoubleDragon.exe file.

image.thumb.png.4cb26eb43d508d0faf20adc0c2159a1a.png

Next go to the Emulation section and make sure the box is unchecked.

image.thumb.png.e8fac657f01362bcbb5d6c2008e0bf92.png

Click OK to save and close.

Now (for testing and process of elimination purposes) open Windows Explorer and navigate to where your "Keyboard2XinputGui.exe" file is located.  Click it and press Enter so that it loads/launches/runs/starts/does-what-it-does.

Now go back to LaunchBox and launch your DD game.

Play it a little.

Do you still get the "error"?  If so, what does it say?

If not, Exit the game as you normally would. (Usually you go to a menu and select "Quit to Windows" or something like that)

You should now be back in LaunchBox.  Press the asterisk on your numpad.  Does "Keyboard2XinputGui.exe" exit?

 

Step 2:

..to follow, depending on the results of Step 1.

  • Game On 1
Link to comment
Share on other sites

I have nofa-king idea what Windjammers 2 is. That's a totally different game, isn't it???

Anyway, since step 1 worked..

Step 2:

Edit your game (again) and go to the Additional Apps section. Click Add Application.  Give it a fancy Application Name like "Keyboard2XinputGui". Next Browse to and select your "Keyboard2XinputGui.exe" file.  Now check the box for Automatically Run Before Main Application.  Click OK.  And Click OK again.

Now the fun part.  Create a new text file and in it put:

SendInput, {NumpadMult}
ExitApp

Save the file somewhere where you won't forget where it is.  Maybe in the same folder as your "Keyboard2XinputGui.exe" file is.  Like with everything else, give it a fancy name like "ExitK2X".  Now rename the file to have an .ahk file extension. like "ExitK2X.ahk".  Be careful that it doesn't get renamed "ExitK2X.ahk.txt".

(Probably could have this last part 1st...) Edit your game once again.  Go to Additional Apps section. Click Add Application.  Give it a fancy Application Name like "Exit Keyboard2XinputGui". Next Browse to and select "AutoHotkey.exe".  You'll find one in /LaunchBox/ThirdParty/AutoHotkey/

In the Application Command-Line Parameters field, type the full path to where you save the .ahk file, and put it in quotes.  Example:

 "D:\Games\Keyboard2Xinput\ExitK2X.ahk"

Make sure you have the correct path.

Now check the box for Automatically Run After Main Application.  Click OK.  And Click OK again.

 

Make sure Keyboard2XinputGui isn't already running.  Launch your game via LaunchBox.

  • Thanks 1
Link to comment
Share on other sites

you are unbelievably good at explaining things over text.  I super wish I had your skills for dealing with my parents and there computer problems.  

You saved the day, works perfectly.....but one final question, i realize now that this game doesn't exit when I press ESC. i think its a steam game kind of but do you know of away to be able to exit it with esc?  If not thats totally cool im guessing this question has been asked a bunch and I can search around for it.

And finally dudeeeeeeeeeeee i am very insulted that you havent heard of windjammers....you need to do me a favor and go and play the greatest game of all time WINDJAMMERS!!!!!!!!!!!! its seems simple on the surface but it is soooooo gosh dang fun, now to play it on an arcade cabinet is the best, but other platforms will do as well i guess.  and this is windjammers 2, just came out and ive never really played it so i cant vouch for it yet but since its a sequel to the greatest game ever its got to at least be ok.  

  • Game On 1
Link to comment
Share on other sites

4 hours ago, sirgubster9 said:

do you know of away to be able to exit it with esc?

Yes. But you'd be back to square one using a script similar to the one you started with.  And we see where that got you. ;)  Also, it always advised to use a games built in exit sequence when available.

Glad to hear the keyboard2Xinput is now working well for you!!

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Hello, I have a set of commands that I saved into a .bat file and am using the "running scrips" section of launchbox to run the .bat file when the program launchs.  The .bat file opens a program and sets some parameters that allows a DMD to run when playing future pinball.  I need it to also run another .bat file too upon exit though which will close the DMD.  I don't know anything about AHK scripting and that is why I wrote the .bat files instead.  Here is what I currently tried to use in the running scripts section and although it worked to launch the first .bat, it did not work to launch the second during exit;

run, "C:\Visual Pinball\VPinMAME\Launchboxscript.bat"

$Esc::
 run, "C:\Visual Pinball\VPinMAME\Launchboxexitscript.bat"
 

Note:  If I knew AHK scripts, I probably wouldn't have had to make .bat files in the first place, but I don't know... Here are the contents of the .bat files if it helps;

 

Launch script;

c                                     <--with a colon like a drive letter (forums turn it into a smiley face...)

cd "C:\Visual Pinball\VPinMAME"
start /min "" "dmdext.exe" mirror --source=futurepinball -q --virtual-stay-on-top --fps 60 -g "[GAMENAME]" --use-ini="C:\Visual Pinball\VPinMAME\DmdDevice.ini"

 

Exit Script;

taskkill /f /im "dmdext.exe"

 

Any help is greatly appreciated!

  

Edited by AceEsCloud
Link to comment
Share on other sites

12 hours ago, AceEsCloud said:

it did not work to launch the second during exit

If you're using FPLoader to launch your tables, it never will.  The Running script only stays active while the 'emulator' (FPLoader.exe in this case) is running.  If I recall correctly, FPLoader is essentially a launcher for 'Future Pinball.exe'.  So as soon as it launches it, it itself closes. Thus, closing out the Running Script making the escape sequence unavailable.  

Steam is the same way.  So if you need to run something after playing a Steam game, you're in the same boat.  'Nature of the beast'.

 

The Fix: Create a new "emulator".

Unless you know how to "wait for an application to not exist [anymore]" (Future Pinball.exe in this case) using a batch file, we'll have to learn ya' some AHK.

Create a new text document.  ("FP-DMD.txt" or whatever)  In there, put:

Run, "dmdext.exe" mirror --source=futurepinball -q --virtual-stay-on-top --fps 60 -g "[GAMENAME]" --use-ini="C:\Visual Pinball\VPinMAME\DmdDevice.ini", C:\Visual Pinball\VPinMAME, Min

Run, "C:\Future Pinball\BAM\FPLoader.exe" /play /exit /open "%1%"
Sleep, 10000

While WinExist("ahk_exe Future Pinball.exe")
  sleep 700

Process, Close, dmdext.exe
ExitApp

Adjust the 2nd Run command to point where your FPloader.exe is located.

Save to somewhere convenient to you, Close and change the file extension to .ahk ("FP-DMD.ahk").  Be careful that it's not saving it as ""FP-DMD.ahk.txt".

In LaunchBox, Add a new Emulator.

  • Name the emulator (FP-DMD or whatever you want)
  • Browse to and set the Application Path to ..\LaunchBox\ThirdParty\AutoHotkey\AutoHotkey.exe
    • Note: once selected, LaunchBox will show it as a relative path.
  • In the Default Command-Lin Parameters: enter the full path to the AHK file you created, in quotes.
  • In the Associated Platforms section (select it on the left), Add "Future Pinball" (or whatever the exact name of your platform is).
  • Assuming all your FP tables will be using dmdext, check the box for Default Emulator.
    • You'll probably be asked, Do you want to make this the default emulator?. Yes.
  • Click OK to save and close.
  • Play a table (or two)

image.thumb.png.94486227cd91aa91269631f66e35d229.png

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...