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: AutoIt script complications with MAME  (Read 2687 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!
AutoIt script complications with MAME
« on: January 07, 2011, 01:06:04 pm »
Hello everyone-
    I use Mala as my front end and am one of the unfortunate few people who suffer from the "loss of focus" problem where upon exiting MAME that Mala is not the application in focus.   So you have to left click on Mala to get it back in focus.   Yes, I am aware there is a post about this problem in the Mala forum, and I've tried everything in there to no avail.  So I've decided to write my own autoit script to simulate a left mouse click after the exit button is pressed.    The script is short and sweet, here is the code:

Code: [Select]
HotKeySet("h", "Actions")

While 1
        Sleep(100)
WEnd


Func Actions()
        If ProcessExists("Mala.exe") Then
                HotKeySet("h")
                Send("h")
                Sleep(950)
                MouseClick("left")
                HotKeySet("h", "Actions")
              
        End
EndFunc


The H key is my Exit button in MAME, so that's why H is in the code like that.   The ProcessExists check is so that this will only act this way if Mala is running.   I just didn't want some strange behavior when doing maintenance every time I typed H.  

When I am in Mala this script seems to work fine.  The H key is still sent via the Send command, and a left click is simulated.   Now my problem is that when I am running MAME and I press my H key to exit, nothing happens.    Does anyone know if there's a reason why MAME would not see my Send("h") command?  Any ideas?

Thanks!

brian_hoffman

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 131
  • Last login:July 02, 2011, 09:02:20 pm
Re: AutoIt script complications with MAME
« Reply #1 on: January 07, 2011, 07:44:32 pm »
Im an AutoHotkey guy but it seems like your script is capturing the H key so mame never gets it.
AHK will do the same thing but you can specify to let it pass through as well by adding a ~ before the key.

So

h::
Send, Leftclick

would read

~h::
Send, LeftClick

You can try it, they are very similar... Im sure AI will let you do it too. Just not sure the correct usage for AI

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: AutoIt script complications with MAME
« Reply #2 on: January 07, 2011, 08:22:49 pm »
Hi, thanks for responding.   I actually came across this link a few hours ago:

http://www.autoitscript.com/forum/topic/99704-my-script-is-halted-while-mame-is-running/

I don't know if what it says in it is true, but it did sound like someone else was able to get it to work in AHK.   So, much like your recommendation, I started to write it in AHK instead.   This is what I had come up with:
Code: [Select]
~h::
Process, Exist, MaLa.exe
If (ErrorLevel != 0) ; If it is not running
   {
    Sleep, 750
    Send {Click}
   }
return

What's curious about this is that the above script works on this computer, the one that I wrote it on.   Then I compile it in AHK into an EXE.   I put this EXE on my arcade machine computer.   And it does NOT work on that computer.   Well, it half works.   For some reason, on my MAME computer, it will recognize that the H key is pressed, and it will do the pause and left click part.  But it does not let the letter h pass through.    Same script, two computers, and it works on one and only half on the other.  Can you think of any reason why that might be?   Do you need to have AHK installed on the computer for it to work or something?  I do not have AHK installed on the MAME computer, so I am unsure if that has anything to do with it.

Any ideas for me?  Appreciate the help!

brian_hoffman

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 131
  • Last login:July 02, 2011, 09:02:20 pm
Re: AutoIt script complications with MAME
« Reply #3 on: January 07, 2011, 09:26:24 pm »

Are you sure the script isnt working.. you can try changing it up a little.

~h::
Process, Exist, notepad.exe
If (ErrorLevel != 0) ; If it is not running
   {
    Sleep, 750
    Msgbox, Notepad is running.
   }
return

On second thought you may want to use the "winactivate" to bring mala into focus.
« Last Edit: January 07, 2011, 09:31:14 pm by brian_hoffman »

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: AutoIt script complications with MAME
« Reply #4 on: January 07, 2011, 11:30:10 pm »
Well, I was positive it wasn't working.   But I have recompiled it, for what feels like the 100th time, restarted the computer and transferred a new copy over to my MAME pc.  Now it works!    I have no idea which of those things fixed the issue, but I am not going to think about it any more.   It works, and I am happy.   At any rate, here is the final version of my AHK code:

Code: [Select]
#NoTrayIcon

~h::
Process, Exist, MaLa.exe
If (ErrorLevel != 0) ; If it is not running
   {
    Sleep, 750
    Send {Click}
   }
return


So anyway, I appreciate the help.  If I play around with this method and it gives me problems, I might look into the winactivate command to test out next.   Thanks again!