Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Pause/Exit on one key - Autohotkey script that works and lights LEDBlinky  (Read 2162 times)

0 Members and 1 Guest are viewing this topic.

bperkins01

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 895
  • Last login:September 24, 2023, 02:13:35 pm
  • Plenty of skills.. gaining experience..
Hi Everyone,

A design feature of my machine is that I wanted a single key for Pause/Escape.  I found info on getting Autohotkey working with Mame and all sorts of old information about recompiling Mame, etc..  What I did not find was something current that worked.  I adapted the script I found (with credit to the original author) and made a few changes.

Here is what I have working:

Bigbox 8.3
Mame 0.199
LedBlinky 6.5.0.1
Autohotkey 1.1.26.01
Windows 10

i.e.  All very current stuff.

Here's what happens:
   When in Bigbox     - the Pause/Exit key is mapped to Escape and is RED.
   When Mame loads - the key is turned to Orange and it is a Pause key...
                                       Unless you hold it for 1.6 seconds, at that point it turns RED and sends an Escape to Mame exiting the game..

To use it - you really need to do a few things:
Set the Escape key to Red in the Front End panel in LEDBlinky so that its always RED when using BigBox
Put the AHK script in the Platform / Autohotkey script tab in Bigbox (which makes things easier actually)
keyboardprovider IN mame.ini MUST BE SET TO dinput
Then be able to interpret some of the documentation in the script and set things up..

I've been messing with this off and on for a while now and finally got to the point where I focused on it enough to get it all working.  I may go back and see if I can make it even a bit more efficient - I had to learn some Autohotkey as part of this so it may not be as clean as it could be..
There is a fair amount of interaction between all of the pieces - but it works..  My Pause/Escape button changes functionality and color depending on the context its in..
Hope I save others out there some time..

*****************************************************************************************************************

#NoEnv      ;Recommended for performance and compatibility with future AutoHotkey releases.
#Warn       ;Enable warnings to assist with detecting common errors.
#SingleInstance force

SendMode Event                  ;Works with Mame!  Sendmode Input does not seem to work in Mame
SetWorkingDir %A_ScriptDir%     ;Ensures a consistent starting directory.
SetKeyDelay -1,110              ;For Mame to get the inputs

/*
ORIGINAL AUTHOR: WXFORECASTER 10/12/10
DESCRIPTION: DESIGN OVERRIDE SUCH THAT A SINGLE KEY PRESS AND KEY HOLD
             GENERATE DIFFERENT FUNCTIONALITY

Updated:  7/31/18  - Bob Perkins - customized for MAME and my environment
V2.0
*/

/*
BEGIN HOLDESCAPE CODE
SET USER DEFINED VARIABLES BELOW
FOR MAME TO ACCEPT AHK SCRIPTS keyboardprovider IN mame.ini MUST BE SET TO dinput!
*/
timeToExit := 1.6            ;time in seconds key must be pressed before sending exit (this can be a decimal e.g. 1.5)
pauseKey := "p"            ;your MAME pause key.  If using letter, be sure to put in quotes (e.g. "n")
exitKey := "Esc"             ;your MAME exit key.  If using letter, be sure to put in quotes (e.g. "n")
exitScript := 0            ;0= leave script running, 1= close script when the MAME exit key is fired

/*
LEDBLINKY SPECIFIC SETTINGS
PAUSE_EXIT is the name of the dual purpose key set in GenLEDBlinkyInputMap.exe
*/ 

LedBlinkyexe := "C:\Users\Arcade Machine\Lakeside_Arcade_Software\LEDBlinky\Ledblinky.exe"    ;Full path to Ledblinky
Led_Red := "PAUSE_EXIT`,R`,48|PAUSE_EXIT`,G`,0"                                               ;Comma's need to be escaped!
Led_Orange := "PAUSE_EXIT`,R`,48|PAUSE_EXIT`,G`,24"                                           ;Comma's need to be escaped!

;Make it so the following code only works if MAME is the active window
#IfWinActive ahk_class MAME
{
        ;Establish Hotkey Mapping based on the emulate key above and trigger a chunk of code below (lblPauseExit)
        LedBlinkySet(Led_Orange)                ;Make the Pause key Orange
        Hotkey, $%exitKey%, lblPauseExit
}
return

lblPauseExit:
KeyWait %exitKey%, T%timeToExit%
      if ErrorLevel = 1 ;timeout was reached...exit MAME
      {
              send {Blind} {%exitKey% downtemp} ;Send MAME Exit
              send {Blind} {%exitKey% up}
              LedBlinkySet(Led_Red)
              if (exitScript = 1)
                      ExitApp
      }
      else
      {
         send {Blind} {%pauseKey% downtemp} ;Send MAME pause/unpause
         send {Blind} {%pauseKey% up}
         LedBlinkySet(Led_Orange)
      }     
return

LedBlinkySet(MyColor)
{
        Global LedBlinkyexe
        Run "%LedBlinkyexe%" "14" "%MyColor%"       ;LedBlinky expects 2 parameters  14=light LED
}

***************************************************************************************
« Last Edit: August 08, 2018, 10:49:37 pm by bperkins01 »
My Arcade Cabinet Build and other projects here:
Centipede, Joust, Joust Cocktail, Asteroids, Galaga, Ms. Pacman Cabaret, Defender, Space Invaders Cocktail
https://bperkins.wordpress.com/

Titchgamer

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 4222
  • Last login:December 17, 2023, 08:05:48 am
  • I have a gaming addiction.....
Nice idea for a script, I use hotkeys for the same purpose but ideal solution if you dont have hot keys.