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: Scripting to remap key presses depending on what emulator is running.  (Read 1331 times)

0 Members and 1 Guest are viewing this topic.

markronz

  • We traced the call, and it came from....INSIDE YOUR ARCADE MACHINE!
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 821
  • Last login:April 12, 2019, 12:03:08 am
  • Game on!
In order to make all my emulators cab friendly, I was thinking of writing a script to help remap some keys.   Like I think I have the Load button on my cab set to the letter L.   For one emulator, the load command might be something like Ctrl+L (not remappable) for example.   For another emulator it might be something like F1.  So what I need to do is change the L key press into something else, determined by what emulator is in focus.  Now for all emulators, I was able to map my controls, obviously, but the admin buttons are not so easy (Exit, Reset, Pause, Config, Save, and Load)

So what I think my script will need to do is this:

Determine what emulator is currently running and currently in focus.
Remap the keys to the appropriate key presses for that particular emulator.
Poll every say 5 seconds (is that overkill?) to see what emulator is currently running at that time.

I wish all emulators were as flexible as MAME where you can define controls for EVERYTHING!  But sadly, we are not so lucky...

Now, I found a few links out there on how to tell what Window is in focus.  And I've also found some links for how to remap key presses.  So I am not looking for information on how to script those per say.   I guess I just have a few questions.

Has anyone done something similar in the past?  It seems like anyone who has multiple emulators, beyond MAME, would run into this same problem.   How have others solved it?  Or if you've written a script for yourself to do something similar, do you think you could provide me with it so that I have somewhere to start?

Do you think having a script running and checking for what emulator is running, like every 5 seconds, would affect the performance of the computer?   It seems like it'd be a simple script for the computer, and wouldn't take up a lot of processor, but I thought I'd ask to see what others thought.  Perhaps one of these scripting languages would have a "WhenWindowInFocusChanges" type event that I could use instead of polling every 5 seconds.   I haven't gotten to look into this too in depth yet.  I thought I would check to see what others have done.  No need to start from scratch if I don't have to!

Thanks!

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9272
  • Last login:Today at 03:57:04 pm
  • ...
Re: Scripting to remap key presses depending on what emulator is running.
« Reply #1 on: December 07, 2010, 02:22:39 pm »
You can probably accomplish everything you want with Mala Hotkeys.

If you want to do it with Autohotkey though, just have an emulator specific script launch
with the emulator and exit when you press whatever button exits the emulator.
End the script with something like this:

ESC::Process, Close, NAOMI.exe
ExitAPP
return

That way, the script is only running when the emulator is running.
« Last Edit: December 07, 2010, 02:28:34 pm by BadMouth »

markronz

  • We traced the call, and it came from....INSIDE YOUR ARCADE MACHINE!
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 821
  • Last login:April 12, 2019, 12:03:08 am
  • Game on!
Re: Scripting to remap key presses depending on what emulator is running.
« Reply #2 on: December 07, 2010, 03:27:38 pm »
That's actually a really good point.   I totally forgot about the Mala Hotkeys.  I will have to check that out when I get home to see if I can get it to work!

And if I do end up having to create a script, you made another great point, that I should just launch an emulator specific script each time the emulator is opened.  Rather than have some master script running and polling for window names all the time.  Your idea makes MUCH more sense!

Thanks so much for your input!

wikee

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 5
  • Last login:August 18, 2021, 05:31:34 am
Re: Scripting to remap key presses depending on what emulator is running.
« Reply #3 on: December 07, 2010, 03:37:36 pm »
you can do it easily with AHK (and with very few lines), its what i use in my cab for some emus or pc games :)


EVEGames

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 117
  • Last login:February 15, 2018, 05:14:39 pm
Re: Scripting to remap key presses depending on what emulator is running.
« Reply #4 on: December 08, 2010, 12:11:27 pm »
You can probably accomplish everything you want with Mala Hotkeys.

If you want to do it with Autohotkey though, just have an emulator specific script launch
with the emulator and exit when you press whatever button exits the emulator.
End the script with something like this:

ESC::Process, Close, NAOMI.exe
ExitAPP
return

That way, the script is only running when the emulator is running.

Alternately, depending on what keyboard encoder you use, you could launch an emulator-specific batch script to remap your encoder, and another to map it back to the standard MAME keys when you exit the emulator.  To do this, you would need an encoder capable of on-the-fly reprogramming via batch file (such as the IPac), and you would need a front-end with "runbefore" and "runafter" capabilities (such as 3DArcade).  You would also want to put a batch script in your Startup menu to remap the encoder to the MAME standard keyset, in case the cabinet gets unexpectedly powered-down while the encoder was mapped to an alternate keyset.

Just throwing another option on the table for ya.  :)