Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

@W4rCh1ld You only need to put it in the Running AutoHotkey Script tab under Edit Emulator. (A little confusing. But ya, just the one location)

If Kronos is running (either through LaunchBox or directly from Windows), if you 'manually press' Ctrl+Q on the keyboard, will it exit the game (and close the emulator)?

Are you using just the keyboard? Or trying to get this to work with a controller [also]?

Link to comment
Share on other sites

@JoeViking245 Ok cool, that'll stop me having to double boot to check both locations, as the other said exit i though i may have got the wrong box, but as all the other exit scripts i have worked from the running i kinda figured that was the case. Yes when Kronos is running both on its own and via launchbox the manual Ctrl+Q work on the keyboard and close... as does the Alt + Enter to go fullscreen etc. I am using both keyboard and controller, alot of the ones i have working i then set to use a twin press of Start and Select to make an Esc keypress.

Link to comment
Share on other sites

@launcherbox Assuming it's a Windows game... Can you write a batch file that has the commands to mount the disc (mount.bat).  And then another one that un-mounts it (unmount.bat).  Then in LaunchBox, have the 'game' point to the exe, an Additional app checked to Run Before Main Application (mount.bat), and another Additional App checked to run After Main Application (unmount.bat).

Otherwise, if you have your steps 1 and 2 working, step 3 would be something along the lines of 

Sleep, 7000                                                     ;give time (7 seconds?) for CivIIG to load [if it's not already]
Loop
{
   if !WinExist("ahk_exe Civilization_II_Gold.exe")             ;if the exe file is not running anymore
   {
      Run, "D:\DameonTools\unmount.com D:\MyGames\CivIIG.nrg"   ;ummount the disc
      Return                                                    ;and exit the script
   }
}

Obviously fixing the games exe filename and the path/commands/etc for un-mounting the disc.  And depending on the rest of your code, "Sleep" may or may not be required.

  • Thanks 1
Link to comment
Share on other sites

@JoeViking245 Thanks for you help, but neither of these worked either, it's not a windows game, Kronos is a Sega Saturn Emulator - a Yabause fork (Links are on this Youtube), i have no idea why i cannot get a close command to work. If anybody has anymore ideas (or is willing to test it, for a solution that'd be cool).

 

 

Edited by W4rCh1ld
details
Link to comment
Share on other sites

13 minutes ago, W4rCh1ld said:

@JoeViking245 Thanks for you help, but neither of these worked either, it's not a windows game, Kronos is a Sega Saturn Emulator - a Yabause fork (Links are on this Youtube), i have no idea why i cannot get a close command to work. If anybody has anymore ideas (or is willing to test it, for a solution that'd be cool).

 

Just change it in Kronos to be "Escape". Open Kronos and in >File>Settings go to the Shortcuts tab and change &Quit from "Ctrl+Q" to "Escape". That's what I did and it works fine.

  • Thanks 1
Link to comment
Share on other sites

On 11/19/2020 at 9:06 PM, JoeViking245 said:

@launcherbox Assuming it's a Windows game... Can you write a batch file that has the commands to mount the disc (mount.bat).  And then another one that un-mounts it (unmount.bat).  Then in LaunchBox, have the 'game' point to the exe, an Additional app checked to Run Before Main Application (mount.bat), and another Additional App checked to run After Main Application (unmount.bat).

Otherwise, if you have your steps 1 and 2 working, step 3 would be something along the lines of 


Sleep, 7000                                                     ;give time (7 seconds?) for CivIIG to load [if it's not already]
Loop
{
   if !WinExist("ahk_exe Civilization_II_Gold.exe")             ;if the exe file is not running anymore
   {
      Run, "D:\DameonTools\unmount.com D:\MyGames\CivIIG.nrg"   ;ummount the disc
      Return                                                    ;and exit the script
   }
}

Obviously fixing the games exe filename and the path/commands/etc for un-mounting the disc.  And depending on the rest of your code, "Sleep" may or may not be required.

That worked a charm, thank you so much! I was scratching my head for ages with that one, but just couldn't get the syntax correct for the check if not running then unmount part. Thank you again for your help.

 

The final script for the game Civ II Gold Multiplayer (with corrected exe name, and command for Daemon tools to unmount) for Windows is:

 

Sleep, 7000                                                     ;give time (7 seconds?) for CivIIG to load [if it's not already]
Loop
{
   if !WinExist("ahk_exe civ2.exe")             ;if the exe file is not running anymore
   {
      Run "C:\Program Files\DAEMON Tools Lite\DTCommandLine.exe" --unmount_all   ;ummount the disc
      Return                                                    ;and exit the script
   }
}

 

  • Game On 1
Link to comment
Share on other sites

Ok I'm back...lol

Still struggling to get X360CE to auto close after exiting Killer Instinct.  I am trying to use a simple .bat script that works in all other scenarios using it as an additional app that closes x360ce after the game exits.  Works great.

When I use it as an additional app with Killer Instinct, (Steam game launched with game .exe not through Steam) it closes X360CE right after it launches...I've tried setting up steam bootstrap (or whatever it's called) as a "game" in the Windows platform and setting up the .bat to run after the game exits but it does nothing, X360CE remains open...Is there another possible way to accomplish what I am failing at? lol...

Link to comment
Share on other sites

1 hour ago, rom116 said:

Steam game launched with game .exe not through Steam

Even though you're using the games' exe, it still redirects to Steam.exe.

So what's happening is you load X360CE, then 'game.exe' loads, this then loads Steam.exe and 'game.exe' closes.  At this point your script sees your original "game.exe" close so it then closes X360CE.  And the game plays on.

I don't know off hand how to do it in a batch file, but you could do something similar to the post right above yours and compile the script to an exe.  Then have this Run Before Main Application.

Sleep, 7000                                     ;give time (7 seconds?) for Steam.exe to load [if it's not already]
Loop
{
   if !WinExist("ahk_exe Steam.exe")             ;if the exe file is not running anymore
   {
      Run "D:\X360CE\x360ce-Killer.exe"   
      Return                                                    ;and exit the script
   }
}

 

Link to comment
Share on other sites

Ok, so to make sure I'm clear on this.  I would copy the text above into a text file and give it a name with an .exe extension and run it as an additional app? 

And if that is correct, can I point it to the existing .bat file?  Or do I change the extension of the .bat file to an .exe file?  Sorry for the noobish questions.  I thought I was pretty cool when I created the .bat...lol

Bat file text below

c:\windows\system32\cmd.exe /c c:\windows\system32\TASKKILL.exe /F /IM x360ce.exe
 

Edit- I think I am figuring it out.  Create an auto hot key script that runs with each windows game?  Correct?  Then to create the .exe file to kill x360ce, can I just create the same text file I used for the .bat and give it an .exe extension?

Edited by rom116
Link to comment
Share on other sites

15 hours ago, rom116 said:

I think I am figuring it out. 

Close.  ;)

But I think I might have been partially wrong when I said the game redirects itself to steam.exe.  

I think what happens is, if Steam is not running [in the background] (and it may do it anyway if it is), when you launch a 'steam_game.exe', it closes (exits) then opens Steam, then reopens the steam_game.exe.  The following worked for Harry Potter [Years 1-4].

Start your Steam games (the ones that are 'game_name.exe') like you did before.  As in, just point to the games' exe file.

image.thumb.png.17635c13caea80d4eccb6bec82c66889.pngStart you x360CE like however you did before.

Create a new batch file with this text in it.  This said file will have a ".bat" file extension.  (BTW, you can never just change a file extension to .exe and have it work.) Under Additional Apps, click Add Application and point to this new .bat file.  Now 'check'  "Automatically Run Before Main Application" and click OK.

@echo off
Timeout 20 /nobreak
:start
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq LEGOHarryPotter.exe"') DO IF %%x == LEGOHarryPotter.exe goto start
goto closed
:closed
c:\windows\system32\cmd.exe /c c:\windows\system32\TASKKILL.exe /F /IM x360ce.exe

What this batch file is supposed to do is... when you start the game in LB, it (the batch file) will 'put itself in the corner for a timeout' for 20 seconds.  (This should be sufficient time for your game to do whatever the heck is going on in the background.)  It will then check to see if LEGOHarryPotter.exe is running (which at this point it should be). It will keep checking until [when you exit the game] LEGOHarryPotter.exe is no longer running.  When it's not, it will then execute the TASKKILL operation.

Using this method you will of course need to change "LEGOHarryPotter.exe" (in TWO locations) to whatever the name of your executable is.  And ya, a different batch file for each game you need to use this for.

  • Like 1
Link to comment
Share on other sites

1 hour ago, JoeViking245 said:

Close.  ;)

But I think I might have been partially wrong when I said the game redirects itself to steam.exe.  

I think what happens is, if Steam is not running [in the background] (and it may do it anyway if it is), when you launch a 'steam_game.exe', it closes (exits) then opens Steam, then reopens the steam_game.exe.  The following worked for Harry Potter [Years 1-4].

Start your Steam games (the ones that are 'game_name.exe') like you did before.  As in, just point to the games' exe file.

image.thumb.png.17635c13caea80d4eccb6bec82c66889.pngStart you x360CE like however you did before.

Create a new batch file with this text in it.  This said file will have a ".bat" file extension.  (BTW, you can never just change a file extension to .exe and have it work.) Under Additional Apps, click Add Application and point to this new .bat file.  Now 'check'  "Automatically Run Before Main Application" and click OK.


@echo off
Timeout 20 /nobreak
:start
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq LEGOHarryPotter.exe"') DO IF %%x == LEGOHarryPotter.exe goto start
goto closed
:closed
c:\windows\system32\cmd.exe /c c:\windows\system32\TASKKILL.exe /F /IM x360ce.exe

What this batch file is supposed to do is... when you start the game in LB, it (the batch file) will 'put itself in the corner for a timeout' for 20 seconds.  (This should be sufficient time for your game to do whatever the heck is going on in the background.)  It will then check to see if LEGOHarryPotter.exe is running (which at this point it should be). It will keep checking until [when you exit the game] LEGOHarryPotter.exe is no longer running.  When it's not, it will then execute the TASKKILL operation.

Using this method you will of course need to change "LEGOHarryPotter.exe" (in TWO locations) to whatever the name of your executable is.  And ya, a different batch file for each game you need to use this for.

Thanks man.  I'll test this out today and let you know.  Happy Thanksgiving bro.

Link to comment
Share on other sites

Hi together,

i need help to setup an ahk script for detetcting joysticks and send a keypress when a detected joystick lost connection.

 

Background: recently i played nes games over retroarch with a 8bitdo controller. it happens two times that the controller turns off without a reason. Now i want a script that sends the pause key to retroarch when one of the connected controller lost connection. i use them over bluetooth and not wired.

 

Anybody out there who can help me out?

Link to comment
Share on other sites

12 hours ago, JoeViking245 said:

Close.  ;)

But I think I might have been partially wrong when I said the game redirects itself to steam.exe.  

I think what happens is, if Steam is not running [in the background] (and it may do it anyway if it is), when you launch a 'steam_game.exe', it closes (exits) then opens Steam, then reopens the steam_game.exe.  The following worked for Harry Potter [Years 1-4].

Start your Steam games (the ones that are 'game_name.exe') like you did before.  As in, just point to the games' exe file.

image.thumb.png.17635c13caea80d4eccb6bec82c66889.pngStart you x360CE like however you did before.

Create a new batch file with this text in it.  This said file will have a ".bat" file extension.  (BTW, you can never just change a file extension to .exe and have it work.) Under Additional Apps, click Add Application and point to this new .bat file.  Now 'check'  "Automatically Run Before Main Application" and click OK.


@echo off
Timeout 20 /nobreak
:start
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq LEGOHarryPotter.exe"') DO IF %%x == LEGOHarryPotter.exe goto start
goto closed
:closed
c:\windows\system32\cmd.exe /c c:\windows\system32\TASKKILL.exe /F /IM x360ce.exe

What this batch file is supposed to do is... when you start the game in LB, it (the batch file) will 'put itself in the corner for a timeout' for 20 seconds.  (This should be sufficient time for your game to do whatever the heck is going on in the background.)  It will then check to see if LEGOHarryPotter.exe is running (which at this point it should be). It will keep checking until [when you exit the game] LEGOHarryPotter.exe is no longer running.  When it's not, it will then execute the TASKKILL operation.

Using this method you will of course need to change "LEGOHarryPotter.exe" (in TWO locations) to whatever the name of your executable is.  And ya, a different batch file for each game you need to use this for.

This did it man.  Thanks a ton.  This was the last "If this would just work my arcade machine would be perfect" situation I couldn't figure out.  You rock!

  • Game On 1
Link to comment
Share on other sites

So this has evolved quite a bit since my last post in here, and basically everything is working as intended except for one specific thing. It's not a huge deal because it's essentially a failsafe but it's annoying me that it's not working nevertheless, so I'm hoping someone has some ideas. The section in red is the problem. Essentially what I want is for the entire script to clean up and shut down if Retroarch or CDisplayEx closes. As it is, it only happens when Retroarch closes. I've tried using SetTimer to alternate between the two Process, WaitClose functions but didn't have any luck there. I've tried placing it under the hotkey for Function2 but then that hotkey no longer worked. This seems like it should be something simple but I've just been beating my head against a wall on this one.

#SingleInstance Force
#WinActivateForce

Gui, +AlwaysOnTop
Gui, -Caption            ;removes caption and border
Gui, color, Black                ; sets window color
Gui, Add, Picture, W%A_ScreenWidth% H%A_ScreenHeight%,
Gui, Show, , Blocker

SetTitleMatchMode, 2
WinWait, Cdisplayex
WinSet, Transparent, 0, ahk_exe CDisplayEx.exe
WinWait, RetroArch VICE
WinActivate, RetroArch VICE
Sleep, 200
Gui, -AlwaysOnTop
Gui, Hide
Hotkey, ~NumpadSub & NumpadEnter, Function1

Process, WaitClose, Retroarch.exe
Winclose, Cdisplayex
Gui, Hide
run, nomousy.exe
Process, Close, nomousy.exe
ExitApp

Process, WaitClose, CDisplayEx.exe
Gui, Hide
run, nomousy.exe
Process, Close, nomousy.exe
ExitApp

Return

Function1:
run, nomousy.exe /hide
Gui, Show, , Blocker
SetTitleMatchMode, 2
WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe
WinActivate, Cdisplayex
WinSet, Transparent, 0, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 20, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 40, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 60, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 80, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 100, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 120, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 140, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 160, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 180, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 200, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 220, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 240, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, Off, ahk_exe CDisplayEx.exe
Gui, Hide
  Hotkey, ~NumpadSub & NumpadEnter, Function2

Return

Function2:
Gui, Show, NA, Blocker
SetTitleMatchMode, 2
WinSet, Transparent, 240, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 220, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 200, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 180, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 160, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 140, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 120, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 100, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 80, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 60, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 40, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 20, ahk_exe CDisplayEx.exe
Sleep, 10
WinSet, Transparent, 0, ahk_exe CDisplayEx.exe
Gui +AlwaysOnTop
Sleep, 250
WinActivate, RetroArch VICE
Sleep, 250
WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe
Gui -AlwaysOnTop
Gui, Hide
run, nomousy.exe
  Hotkey, ~NumpadSub & NumpadEnter, Function1  
Return

  • Thanks 1
Link to comment
Share on other sites

11 hours ago, Zombeaver said:

Process, WaitClose, Retroarch.exe
Winclose, Cdisplayex
Gui, Hide
run, nomousy.exe
Process, Close, nomousy.exe
ExitApp

Process, WaitClose, CDisplayEx.exe
Gui, Hide
run, nomousy.exe
Process, Close, nomousy.exe
ExitApp

I don't know how efficient this would be and might need some tweaking, but wouldn't something like this work:

Quote

while (WinExist ( "Retroarch" )
{

    if WinExist ( "CDisplay" )
    {
        ; both windows open, do nothing
    } else {
        ; CDisplay doesn't exist, so kill Retroarch
        Process, WaitClose, Retroarch.exe
        Gui, Hide
        run, nomousy.exe
        Process, Close, nomousy.exe
        ExitApp
    }
}

; we've dropped out of loop since Retroarch doesn't exist
Process, WaitClose, CDisplayEx.exe
Gui, Hide
run, nomousy.exe
Process, Close, nomousy.exe
ExitApp

Might need a Wait in the loop so you are constantly polling so much.

Also, instead of redefining the hotkey each use, might be simpler and cleaner to call a function that just maintains a simple boolean toggle and use that alternate calling the 2 functions.

So you would have Hotkey, ~NumpadSub & NumpadEnter, Flip

Quote

Flip::
toggle := !toggle 
goto, % toggle ? "Function1" : "Function2" 
return

and remove the hotkeys from Function1 and Function2.

Can't test this myself right now, but hopefully logic makes sense and helps.

Edited by Headrush69
Add info
Link to comment
Share on other sites

@Zombeaver   Process,WaitClose  will hang up everything in the code that is after it, until it satisfied (RA closes).

@Headrush69's code is much shorter and to the point.  Whereas I tend to be more 'long-winded'. lol 

So if nothing else, chalk this one up as just another approach. ;)   Note, there's an added method [ ProcessExist() ] at the end.

Loop
{
   IF ProcessExist("Retroarch.exe")
   { }		
   Else
   {
      Winclose, Cdisplayex
      Gui, Hide
      run, nomousy.exe
      Process, Close, nomousy.exe
      ExitApp
   }

   IF ProcessExist("CDisplayEX.exe")
   { }		
   Else
   {
      Gui, Hide
      run, nomousy.exe
      Process, Close, nomousy.exe
      ExitApp
   }

   Sleep, 2000
} 

ProcessExist(Name){
	Process,Exist,%Name%
	return Errorlevel
}

 

Link to comment
Share on other sites

7 minutes ago, JoeViking245 said:

 

@Headrush69's code is much shorter and to the point.  Whereas I tend to be more 'long-winded'. lol 

 

LOL, stayed long winded. Verbose code is always better to me. ?

I get lazy sometimes using the phone to post, especially code. You'd think I'd learn after a while it's not a good tool for that, but seems I'm always running to the computer after to fix all the mistakes I make using it.

Link to comment
Share on other sites

17 minutes ago, Headrush69 said:

I get lazy sometimes using the phone to post, especially code

I would screw it so bad if I tried that! lol  And even though I didn't, I did see a better (code-wise) way to write it. :D  

Loop
{
   IF ProcessExist("Retroarch.exe")
   { 
      IF ProcessExist("CDisplayEX.exe")
      {}
      Else
      {
         Gui, Hide
         run, nomousy.exe
         Process, Close, nomousy.exe
         ExitApp
      }
   }
   Else
   {
      Winclose, Cdisplayex
      Gui, Hide
      run, nomousy.exe
      Process, Close, nomousy.exe
      ExitApp
   }
   Sleep, 2000
} 

ProcessExist(Name){
   Process,Exist,%Name%
   return Errorlevel
}

 

 

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