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: AHK Script or Method to Display Image on MAME Pause?  (Read 8204 times)

0 Members and 1 Guest are viewing this topic.

Necro

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1031
  • Last login:November 29, 2022, 08:22:22 pm
  • Building a 'Classic' MAME Cab
AHK Script or Method to Display Image on MAME Pause?
« on: February 12, 2010, 08:58:52 pm »
Anyone by any chance done this?  I tried using the diff from CPWizard to display an image when MAME is paused but it doesn't seem to work for me at all.  (Yes, I recompiled :) )  - then again, I can't get CPWizard to work at all.

I'm thinking an AHK script that fires off P and still passes the P through would work...

Anyone ever done anything like this or have any other ideas?

(Note: Just getting CPWizard to work isn't actually an option - it's a mirror'd cab so I need to flip all images horizontally)

Neverending Project

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 851
  • Last login:April 06, 2015, 10:07:43 pm
    • Arcade Fixer
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #1 on: February 12, 2010, 10:48:30 pm »
I don't know if Mame will see keystrokes sent by AHK. I'm not sure, but that may be the first hurdle.

If you just flip the image you want to display and save it mirrored, couldn't you still use CPWizard? If you can get it working, of course.

Necro

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1031
  • Last login:November 29, 2022, 08:22:22 pm
  • Building a 'Classic' MAME Cab
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #2 on: February 13, 2010, 12:05:34 am »
...I was under the impression that CPWizard generated images on the fly when used in that fashion.

But, yeah.  Hell, even redoing the bezel artwork zips would be feasible if it uses premade ones.  (And optimal)

Stormrider

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 318
  • Last login:September 28, 2014, 11:01:54 am
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #3 on: February 13, 2010, 05:02:56 am »
If you want scripts to work in, you will have to recompile it with a little change to osd\windows\input.c Find the line #define FORCE_DIRECTINPUT 0 and change it to #define FORCE_DIRECTINPUT 1. That changes raw input to direct input.

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:July 13, 2025, 11:38:27 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #4 on: February 15, 2010, 07:34:42 pm »
Pretty sure you are looking at the problem backwards.  You shouldn't need to send the "p" key rather you just need to know when mame is paused.  I thought cpwizard did this. 

Long story short, if your version of mame is new enough to support outputs then mame sends a "pause" message to any listening app.  Mamehooker supports this and afaik cpwizard as well.  What you want to do is have the app show the image on pause and hide it on unpause.  No keys would have to be sent.  Just make the "p" key your exit key.... you'd press "p" once to bring it up... pressing "p" again would exit but mame would still be paused, and "p" a final time would unpause things.  I don't think the diff patch is really necessary anymore.

headkaze

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2943
  • Last login:August 14, 2023, 02:00:48 am
  • 0x2b|~0x2b?
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #5 on: February 15, 2010, 07:54:26 pm »
Actually with the latest versions of MAME it's even easier. The main problem people had was when you close the app it wouldn't unpause MAME (yeah people are *that* pedantic about pressing 'p' again). So I found another way and that is

To pause

Code: [Select]
PostMessage(hWnd, WM_USER_UI_TEMP_PAUSE, 1, null);
and to unpause

Code: [Select]
PostMessage(hWnd, WM_USER_UI_TEMP_PAUSE, 0, null);
The only problem is you can't use the same pause key as MAME uses otherwise it pauses then unpauses. The bezel patch was really just to unpause MAME but it also was so you could display your controls as an overlayed bezel. CPWizard can generate a bezel file for every game and the patch modifies MAME so pressing pause will show the bezel and unpausing will hide it. This way you never needed CPWizard running to view your controls. But it looks like I have to update the patch for the latest MAME again. Perhaps I could ask MKChamp to add it to his hiscore patch?

EDIT: Actually now that I think about it you could probably use Mame Interop to detect pause first and then send the unpause message to unpause. Never tried that way but it should work and that way you could use the same pause key as MAME.
« Last Edit: February 15, 2010, 07:57:52 pm by headkaze »

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:July 13, 2025, 11:38:27 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #6 on: February 15, 2010, 11:28:37 pm »
Well that sure is a nifty trick.... when did they add that in? What's the value for that constant btw... it might prove handy?

Yeah the interop thing dawned on me just the other day.... been working on johnny 5 to get it out of it's embarrassing non-working state.  Once I get things squared away I want to show you a nifty trick I found regarding control viewers... but it needs more testing first.

But yeah... with your trick and mine combined we should be able to do an auto-pause without all the sketchy reliability we've had in the past.  I'll look into it when I get a chance.

headkaze

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2943
  • Last login:August 14, 2023, 02:00:48 am
  • 0x2b|~0x2b?
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #7 on: February 16, 2010, 02:14:30 am »
Code: [Select]
#define WM_USER             0x0400
#define WM_USER_UI_TEMP_PAUSE         (WM_USER + 6)

Garetmax

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 50
  • Last login:March 01, 2015, 09:17:57 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #8 on: February 10, 2012, 06:50:14 pm »
Hi,

Sorry to resurrect an old thread but Necro posted exactly what I was thinking.

I've started working on my Mame cab again and really want CPWizard to work as its a must have in my opinion.  My problem is that the speed of CPWizard with Mala is way too slow.  It takes 30 sec to a minute to show the control panel view.

I've got Mala as a frontend and really like it much better than a couple others I've tried.  The 2 others I've tried, Hyperspin and Maximus Arcade, I don't like at all.

I've got my control panel all setup in CPWizard and really like it.  It works great outside of Mala when testing but not in Mala.  A quick search and you'll find other Mala users with the same problem.  I don't see people with other frontends talking about this problem.

I did the export bezel process and have all of the control panels in my Mame Artworks folder ready to go.  I go into Mame and can select Show CP and they show up great but I want these to show up with a Mame Pause.

I don't have the skills to do an Autohotkey script like this but think this may be my only option other than changing frontends.  I would compile with the bezel diff patch but those patches are all outdated now also.

I was hoping someone would make an autohotkey script to see the Mame Pause and put up the control panel bezel.
 
Maybe HeadKaze (Master Programmer) or Howard Castro (another Master Programmer) will see this post and help out us Mala users. :)

Thanks,
Scott

nitz

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 507
  • Last login:November 24, 2015, 07:57:29 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #9 on: February 10, 2012, 08:53:37 pm »
I'm thinking your best bet is just switching to another frontend that doesn't have that problem. Though as a Mala fan myself, I can understand if you don't want to do that, so I could try to help you with an ahk solution if you like.

First of all, forget about running in Direct3d if you want to use ahk for this. It can't overlay images on that, at least not out of the box. It's probably possible somehow, but I think it'd be way more trouble than it's worth.

So if you're willing to use directdraw instead, let me know and we'll see about a solution. :cheers:

Garetmax

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 50
  • Last login:March 01, 2015, 09:17:57 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #10 on: February 10, 2012, 10:12:57 pm »
Hi nitz,

That would be awesome if you would help out us Mala users.
I'll change to direct draw if its not on it already.
I'm not at home right now, but let me know if there is anything you need.
I'm running Mame 145 compiled with the hi score diff and Mala 1.7.4.1.  My computer is running Win7 32-bit.


I appreciate your offer.

Thanks,
Scott
« Last Edit: February 11, 2012, 10:09:36 am by Garetmax »

nitz

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 507
  • Last login:November 24, 2015, 07:57:29 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #11 on: February 11, 2012, 06:59:06 pm »
I did the export bezel process and have all of the control panels in my Mame Artworks folder ready to go.  I go into Mame and can select Show CP and they show up great but I want these to show up with a Mame Pause.

I don't really know what "export bezel process" is and am unfamiliar with the Show CP feature as well, but I think I sort of understand what you want to do. You have numerous images named like the roms (ie. pacman.png, galaga.png, sf2.png, etc.) and you would like to be able to press pause in mame and have the image for the game you are playing overlay onto the screen? And then press pause again to make the image disappear and mame resume?

That should be doable. If I'm misunderstanding something here though, let me know. The best way for me to help you out is to have the most detailed explanation of what you want to do that you can give me. :cheers:

Garetmax

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 50
  • Last login:March 01, 2015, 09:17:57 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #12 on: February 11, 2012, 07:41:56 pm »
That is exactly what I want to do - you are 100% correct. :)

The export bezel process is in the CPWizard program which generated my control panel artwork files which are named exactly the same as the rom names.  These are in zip format and have the actual image as a png file.  All of these are in my Mame\artworks folder.  For example, there is a file named 005.zip.  Inside this zip file is the actual 005.png file which is the control panel image I want to display.

The Show CP and Hide CP options are in Mame.  When you run a game in Mame and then push the "TAB" key to show the MAME options, go to "Video Options" and the Show CP and Hide CP will be there.  When show CP is selected, the control panel immediately opens and you can look at the custom control panel I made.  However, then you have to select Hide CP to go back to the game and then have to back out of the video options then the mame options to get back to the game.  

You mentioned "overlay" this control panel image.  I'm not really sure what an overlay image is other than maybe showing the control panel on top of the game image.  I don't really need that.  I just want the png file to show up alone which maybe even uncomplicates this possibly.  I attached the 005.png for reference.


Thanks
« Last Edit: February 11, 2012, 08:11:46 pm by Garetmax »

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:July 13, 2025, 11:38:27 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #13 on: February 11, 2012, 09:35:05 pm »
Ok I'll chime in. 

Mame recently added new categories to the artwork system..... rather than just "bezel"  "overlay" and "backdrop"  we now have "marquee" and "bezel" as well. 

Now these aren't really meant to show your mame cp image... instead they are meant to show the game's original control panel for those rare cases when you really need to see the cp in order to understand what you are supposed to do in the game.  (Maybe the buttons are lighted, ect....)


That being said it is possible to use it for your purposes. 

My best advice to you is to simply sit tight......  these options were only recently added..... adding ui-hot-keys to toggle on and off various artwork elements would be the next logical addition to mame.

Garetmax

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 50
  • Last login:March 01, 2015, 09:17:57 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #14 on: February 11, 2012, 10:41:02 pm »
Ahh, but when will those options be available - 1 month, 6 months, 2 years?

I'm still hoping nitz will whip something up if its not too time consuming or difficult.

Thanks

nitz

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 507
  • Last login:November 24, 2015, 07:57:29 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #15 on: February 11, 2012, 11:38:52 pm »
I'm sure I can do something, but there are some caveats:

1) It's actually gdi you'll need to use for the video and not direct draw. My bad. Gdi is the slowest of all video modes, so make sure you can still run at least most of the games you want to play full speed in that mode before we move ahead with this.

2) Unless you use a pretty old version, you will need to make a small source code change so that mame can accept key presses from a program, and then compile.

3) The zipped pngs are not gonna work. They will all need to be unzipped. Unless you only have a few (but I'm guessing you have hundreds if not thousands), that would be pretty cumbersome to do by hand. Fortunatley, I could help you automate that.

You can try out this test script if you want. This will display the 005.png image over mame when you press p. Mame will not pause though unless you're using an old version. Just put this in an ahk script in the same folder as 005.png, run it, and boot up any game in mame. Press p and the png should show up in the center of the screen. Press p again and it should disappear. It will display the image at it's actual size, but that can be adjusted if need be. This will be a good test to do to make sure it's working the way you want it to before we get too deep into it.

Quote
Gui, Add, Pic, x0 y0, 005.png

Gui, +AlwaysOnTop -Caption +ToolWindow

state = 0

$p::
If (state = 0)
{
state := 1
send {blind} {p downtemp}
send {blind} {p up}
Gui, Show, w640 h480 NA
return
}
If (state = 1)
{
state := 0
Gui, Hide
send {blind} {p downtemp}
send {blind} {p up}
}
return

 :cheers:
« Last Edit: February 11, 2012, 11:40:26 pm by nitz »

Garetmax

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 50
  • Last login:March 01, 2015, 09:17:57 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #16 on: February 12, 2012, 08:41:02 am »
The test script worked just as you described it.

I tried it first without changing the video options.  It would flash and put up the 005.png screenshot but below the mame screen and out of focus.

I then went into the mame.ini config section in Mala to setup gdi.  I didn't see the setting for gdi.  I only see direct draw and d3d.  The direct draw option box was checked and direct 3d was not.  I went to the actual mame.ini and opened it up.  Under  windows video options 'video' it showed d3d which is strange as Mala doesn't show that.  I'm not sure what's going on there.  I typed in gdi and saved, then retested and it puts the control panel right on top of the mame game that is running and looks great.

I'm running the latest Mame at 145 and I do have thousands of the png files.

See attached screenshot.  I was in the Moon Patrol game.

« Last Edit: February 12, 2012, 08:46:25 am by Garetmax »

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:July 13, 2025, 11:38:27 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #17 on: February 12, 2012, 10:08:54 am »
I'm sure I can do something, but there are some caveats:

1) It's actually gdi you'll need to use for the video and not direct draw. My bad. Gdi is the slowest of all video modes, so make sure you can still run at least most of the games you want to play full speed in that mode before we move ahead with this.

2) Unless you use a pretty old version, you will need to make a small source code change so that mame can accept key presses from a program, and then compile.

3) The zipped pngs are not gonna work. They will all need to be unzipped. Unless you only have a few (but I'm guessing you have hundreds if not thousands), that would be pretty cumbersome to do by hand. Fortunatley, I could help you automate that.

You can try out this test script if you want. This will display the 005.png image over mame when you press p. Mame will not pause though unless you're using an old version. Just put this in an ahk script in the same folder as 005.png, run it, and boot up any game in mame. Press p and the png should show up in the center of the screen. Press p again and it should disappear. It will display the image at it's actual size, but that can be adjusted if need be. This will be a good test to do to make sure it's working the way you want it to before we get too deep into it.

Quote
Gui, Add, Pic, x0 y0, 005.png

Gui, +AlwaysOnTop -Caption +ToolWindow

state = 0

$p::
If (state = 0)
{
state := 1
send {blind} {p downtemp}
send {blind} {p up}
Gui, Show, w640 h480 NA
return
}
If (state = 1)
{
state := 0
Gui, Hide
send {blind} {p downtemp}
send {blind} {p up}
}
return

 :cheers:

Read above in this thread.... unless something has changed Hk's Postmessage signal can pause/unpause mame..... what you do is set the pause key in mame to something OTHER than p.... and let your script completely control the pausing and unpausing of mame.  ;)

nitz

  • Trade Count: (+2)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 507
  • Last login:November 24, 2015, 07:57:29 pm
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #18 on: February 12, 2012, 03:17:20 pm »
Yeah, that's probably a better way to go than fiddling with the source actually.

I'm running the latest Mame at 145 and I do have thousands of the png files.

OK, if you want to do this then, I should be able to come up with a script that can unzip everything quickly. My idea is to use 7-zip since it runs from the command line, and then an ahk script to send each filename to the command line one by one.

Unless someone can do it with a batch file and eliminate the need for using 7-zip which I guess would be a slight pain if you don't already have it and have no other use for it. Anyone wanna chime in...

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19427
  • Last login:July 13, 2025, 11:38:27 am
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #19 on: February 12, 2012, 04:32:37 pm »
Actually..... I remembered something form my reject pile.  (Boy if people only knew the crazy stuff I experiment on in-between releases.)


The only way to inject images into a direct3d/ddraw application is to of course write a proxy (wrapper) dll.  That is a lot of work though.  Thankfully this one guy did it for us:

http://www.mikoweb.eu/index.php?node=28

I can confirm that his dll does work with the 32 bit versions of mame quite well and yes, transparent pngs are supported!
 
I initially looked into this as a universal way to overlay data on a video game but eventually abandoned it because the dll doesn't work on 64 bit mame (which is unacceptable for my setup) and it doesn't work well in other emulators. 

It works ok for mame though and you wouldn't have to give up hardware acceleration. 

It has some quirks though.... in mame the drawing area is always square and always to the power of 2.  So to display an image properly you have to create it with enough "white space" to make it fit right.  You put the actual image in the top left corner and add white space to the nearest power....

Example: 

Lets say your screen resolution is 1024x768.... 1024 is the big side and 1024 just happens to be a valid multiple, so we make a 1024, 1024 image and print our actual image in the top left corner.... we then load and display this modified image.

Lets say your screen resolution is 1600x900.... 1600 is the big side but 1600 isn't a good multiple for most video cards... we up it to 2048x2048 and again pu the actual image in the upper-left corner.  It'll show up great.



So you might want to look into that... there are only three calls and it's easy to implement, but as you can imagine it isn't exactly practical for a full-fledged app due to all the funky image manipulation.

Necro

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1031
  • Last login:November 29, 2022, 08:22:22 pm
  • Building a 'Classic' MAME Cab
Re: AHK Script or Method to Display Image on MAME Pause?
« Reply #20 on: February 16, 2012, 11:28:35 am »
So...since I started this thread maybe I should chime in.  I'm currently using GameEx and I have it setup to do this effectively.  I can't recall off the top of my head the software I'm currently using, but I'll check and let you know.

The biggest issue I have is crashes/freezes when pausing certain games...sometimes it's the first time you pause, sometimes the second inthe same game, etc. 

I haven't tweaked this to fixed yet and it's one of the things keeping my cab in the 'work room' vs moving to my main basement still...