Jump to content
LaunchBox Community Forums

Recommended Posts

Posted

I'm using BigBox on a cabinet in a semi public location.  If someone chooses a game and walks away, I didn't want MAME running indefinitely.  I would rather return to BigBox so the next person knows he can choose a game.  I used the following script to exit MAME if there is no input for two minutes.  In LaunchBox's Manage Emulators window, choose MAME and Edit Emulator.  Then, on the AutoHotkey Script tab, enter the following:

Quote

#Persistent
SetTimer, Check, 6000
return

Check:
IfGreater, A_TimeIdle, 120000, Process, Close, {{{StartupEXE}}}

Hope it works for someone else too!

  • 7 years later...
  • 1 year later...
Posted (edited)

Does that AHK script above still work?  I've copied and pasted it into the Running Scripts section under Edit Emulator (Retroarch), but nothing happens after 120 seconds... any game that uses Retroarch (mame-libretro) just keeps running.

I've also used this AHK in Running Scripts with Retroarch a few years ago and it worked well, but I stopped using it.  I wanted to start using it again but it is not working on the latest LB version:

 #Persistent
SetTimer, Check, 6000
return

SendMode Event

Check:
IfGreater, A_Timeidle, 120000
{
   SetKeyDelay, -1, 110
   Send {Escape}
   Sleep, 1000
   Send {Escape}

I'm using Windows 10 Pro, Launchbox version 13.22.  I've tried Beta 13.23 too, but same thing... nothing happens.  It's like the AHK is not executing from Running Scripts when the emulator starts.

I can manually press Escape two times and Retroarch will quit.  So, why can't I do this with AHK in Running Scripts?

Edited by paddyG
Posted
1 hour ago, paddyG said:

Does this AHK script still work?  I've copied and pasted this into the Running Scripts section under Edit Emulator (Retroarch), but nothing happens after 120 seconds... any game that uses Retroarch (mame-libretro) just keeps running.

Windows 10 Pro, Launchbox version 13.22.  I've tried Beta 13.23 too, but same thing... nothing happens.  It's like the AHK is not executing from Running Scripts when the emulator starts.

I've never tested it, but looking at it, it should.  As for running Arcade games using RetroArch vs. stand-alone MAME, that's a different thorn. ;) 

To explain what the script is doing, it's checking every 6 seconds. During "the check", if there's been no keyboard presses or mouse movement for a cumulative of 2 minutes, it will (should) close the app.  So if you touch the mouse at all (or press a key), A_TimeIdle resets to 0.  

To verify the script at least started, below #Persistent, you can add a line MsgBox, script started.  (Though you might not be able to see the message box behind the Loading Screen. And... it might pause the script until you click OK.) 

Posted

Thanks JV... I added MsgBox, script started after #Persistent and disabled -f and startup screen so I could see the game open in RA window.  When I launched the game, I saw the message pop up and it said the script was running.  I clicked ok and the message box closed.  I clicked the RA window to make sure it was active and I watched the game demo play in the active RA window for 5 minutes and it did not exit.  There was nothing disturbing the mouse or keyboard or any other input device, all idle the whole time.  

I have RA set to quit with Escape key, and also "confirm quit" is on, so Escape has to be pushed twice to actually quit RA.  I disabled "confirm quit" to see if that changed anything, but it did not.  I know we verified the script is running, but it seems it is not actually sending the Escape key (x2).

I've also tried this script in Running Scripts, but same... it does not quit Retroarch:

#Persistent
SetTimer, Check, 6000
return

Check:
IfGreater, A_Timeidle, 300000
{
WinClose, ahk_exe {{{StartupEXE}}}
}
return

$Q::
{
WinClose, ahk_exe {{{StartupEXE}}}
}

 

  

Posted
54 minutes ago, paddyG said:

I know we verified the script is running, but it seems it is not actually sending the Escape key (x2).

If you disabled Confirm, it's not even sending Escape once;)  Well, it is actually sending it. It's just that RA is not receiving it.  There's some fancy shmancy things you can do to make it work that way.  But since we're just trying to close the emulator, let's just cut to the chase.  Which is what you did in your last post. But I think (not totally sure), the 2nd Return might be 'causing issues'.  

The Q hotkey is redundant to pressing Escape.  But if you'd rather press Q than Escape, then go ahead and keep it in there.

Lastly, when testing, be sure to wait the   w h o l e   5 minutes (300,000ms) plus 6 seconds +/- for the initial 'check'.

#Persistent
SetTimer, Check, 6000
return

Check:
IfGreater, A_Timeidle, 300000
  WinClose, ahk_exe {{{StartupEXE}}}

;optional
$Q::WinClose, ahk_exe {{{StartupEXE}}}

This worked for me.  (5 minutes was a long arse time to wait for a test. But I waited. ;))

But fortunately/unfortunately, this is the exact same thing as the OP.  Except with a different wait/idle time, using WinClose (which is preferred over Process, Close) and formatting out the WinClose line (which functionally, doesn't make a difference [similar to my 'Q' hotkey]).

That said, not sure what else to tell ya.

Posted

Thanks JV, I tried that script, but no-joy.  Must be some permissions issue with RA.  I'll keep digging.  I'm like a dog with a bone with this.  I might spend the weekend building everything from scratch.  I just wanna play pac-man, man!

Posted

I figured out the culprit is Joy2Key.  When J2K is running, the exit on idle AHK in Running Scripts does not execute... I guess maybe J2K is causing some disturbance to the idle timer in the background.  When I close J2K, and run the game in LB/BB with RA, the AHK runs as expected and closes the game/emulator once the idle time is met. 

Hmmm... how to use J2K and have this script do it's thing at the same time? 

Posted

Google to the rescue!  Had to add "hooks" for mouse and keyboard, and use A_TimeidlePhysical to the AHK.  I changed the idle time to 10000 for testing purposes so I'm only waiting 10 seconds to check results.  So now it looks like this, and it works!  Whoo-Hooo!!!

#Persistent
#InstallKeybdHook
#InstallMouseHook
SetTimer, Check, 6000
return

SendMode Event

Check:
IfGreater, A_TimeIdlePhysical, 10000
{
   SetKeyDelay, -1, 110
   Send {Escape}
   Sleep, 1000
   Send {Escape}
}

Thanks again JV for helping me yesterday... I owe you a very large coffee!

Posted

Well, I spoke too soon.  The running script works too well.  I set the check time to 300000, and the game exited while I was playing!  Back to the drawing board...

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