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: Auto Hot Key script  (Read 2231 times)

0 Members and 1 Guest are viewing this topic.

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Auto Hot Key script
« on: September 15, 2022, 12:50:26 pm »
So I'm trying to figure a way to limit the number of credits that can used during a single game. I came across Auto Hot Key. This script says: If you hit the 5 or 6 key more than 5 times, the key will then no longer work. When hit Esc key to exit out of the game the script stops. The problem is it doesn't work in MAME. It works for other programs like Excel and Outlook.... In MAME the 5 and 6 keys don't work at all. Any ideas?


key5 := 0
key6 := 0

~esc::
key5 := 0
key6 := 0
return

$5::
key5++
if key5 <= 5
{
send, 5
}
return

$6::
key6++
if key6 <= 5
{
send, 6
}
return

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #1 on: September 15, 2022, 07:16:21 pm »
I found this thread: http://forum.arcadecontrols.com/index.php?topic=36930.0 but the link is outdated. Does anyone have the coinlimit.exe and .ini?

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1543
  • Last login:May 15, 2024, 08:00:52 pm
Re: Auto Hot Key script
« Reply #2 on: September 16, 2022, 03:30:34 am »
You just need a version of mame that would work with outohotkey and youll be fine.

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #3 on: September 16, 2022, 09:03:24 am »
I have tried versions .120, .140, .160, .180, .210, .246 all with the same result.....also tried a few 32 bit with same results
« Last Edit: September 16, 2022, 09:47:20 am by spisi »

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #4 on: September 16, 2022, 11:07:59 am »
OK, after much Googling, I saw that I need to edit the source code... I got pretty far (amazed). I had to edit the input.c file from FORCE_DIRECTINPUT   0 to FORCE_DIRECTINPUT   1. I'm getting stuck compiling....Even if I don't edit the input.c file it doesn't compile. Using version .160 (latest source code with input.c)
« Last Edit: September 16, 2022, 12:05:07 pm by spisi »

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #5 on: September 16, 2022, 12:07:25 pm »
This is what I get when I try to compile mame .150 (unedited).

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #6 on: September 16, 2022, 01:29:44 pm »
zanyt13 had a similar problem 10 years ago.

https://www.mameworld.info/ubbthreads/showflat.php?Cat=1&Number=305839&page=&view=&sb=5&o=&vc=1

What path is he talking about? If the path was wrong wouldn't there be a ton more errors?


abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1543
  • Last login:May 15, 2024, 08:00:52 pm

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #8 on: September 17, 2022, 07:05:47 am »
Great thanks Abispac! Their server is down at the moment, I hope it gets back up real soon so I can test it out!  :cheers:

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #9 on: September 17, 2022, 07:34:40 am »
Still not working....What do I do with the postfx.zip file? I extracted it and get a post.fx file. Do I just leave it in the root directory?
It's behaving the same, the weird thing is the 5 and 6 keys becomes disabled completely.....So the script is half working I guess...maybe my script is bad?

key5 := 0
key6 := 0

~esc::
key5 := 0
key6 := 0
return

$5::
key5++
if key5 <= 5
{
send, 5
}
return

$6::
key6++
if key6 <= 5
{
send, 6
}
return

It can't be a bad script though because it works correctly with notepad. Hmmm..... :banghead:
« Last Edit: September 17, 2022, 12:46:55 pm by spisi »

Tiberius

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 46
  • Last login:March 03, 2024, 02:10:01 pm
  • Spent more time fixing than playing
Re: Auto Hot Key script
« Reply #10 on: September 17, 2022, 12:38:50 pm »
I have managed to get this to work with a few variations.

Using latest Mame on Windows 10 - just the normal Mame download no special build

You need to make a change in mame.ini file
Look for # OSD INPUT OPTIONS
and change
keyboardprovider          auto
to
keyboardprovider          dinput

Then save and close file

Change the ahk to the one below and it worked for me - so hopefully will work for you as well

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

key5 := 0
key6 := 0

~esc::
key5 := 0
key6 := 0
return

$5::
key5++
if key5 <= 5
{
Send {5 down}
Sleep, 50
Send {5 up}
}
return

$6::
key6++
if key6 <= 5
{
Send {6 down}
Sleep, 50
Send {6 up}
}
return

Using Wiimotes, Demulshooter and Touchmote as lightguns......does actually work!!!

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #11 on: September 17, 2022, 12:54:41 pm »
Eureka!!! That does the trick! Thank you, thank you, thank you Tiberius!!!

Of course there's still another problem now. When using a batch file to run the script and mame simultaneously, mame doesn't find the roms? There's some roms, roms that I don't even have, and none of them work???


ECHO OFF

START "Coinlock.ahk" "C:\Users\John\Desktop\Coinlock.ahk"

START "mame64.exe" "C:\Users\John\Desktop\MAME64a\mame64.exe"
« Last Edit: September 17, 2022, 01:08:49 pm by spisi »

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #12 on: September 17, 2022, 03:36:41 pm »
I removed the roms folder completely!!! It still shows roms in the list WTH!

Tiberius

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 46
  • Last login:March 03, 2024, 02:10:01 pm
  • Spent more time fixing than playing
Re: Auto Hot Key script
« Reply #13 on: September 17, 2022, 05:19:45 pm »
Mame will show ALL roms it can play whether you have them or not in it's UI unless you are filtering them.

Do you have a complete set of roms that match your mame version or do you just have random roms?

Where are you keeping the roms and have you told Mame the full ROM path in the same in ini file you adjusted earlier?

So a couple of things of things to check out.

But it should work. If mame loads and loads a ROM you know you have adding the ahk to a batch file shouldn't cause any issues.



Using Wiimotes, Demulshooter and Touchmote as lightguns......does actually work!!!

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #14 on: September 17, 2022, 05:34:04 pm »
Thanks Tiberius! I got it working, I needed to add this:

pushd "C:\Users\John\Desktop\MAME64a\"

before this:

mame64.exe ssprint

It's working now. But alas I have (I hope) one last problem. How can I tell AHK about a button? I tried mapping my coin1 & coin2 buttons to 5 and 6 respectively in antimicro. But that did not work. I think I need to specify the buttons in the AHK script. Here's my current script:

#SingleInstance Ignore

key5 := 0
key6 := 0

~esc::
key5 := 0
key6 := 0
return

$5::
key5++
if key5 <= 4
{
Send {5 down}
Sleep, 50
Send {5 up}
}
return

$6::
key6++
if key6 <= 4
{
Send {6 down}
Sleep, 50
Send {6 up}
}
return

I added this above it:

Joy17::
{
Send {5 down}
Sleep, 50
Send {5 up}
}

Joy20::
{
Send {6 down}
Sleep, 50
Send {6 up}
}

My coin1 button is button 17 in Windows (U-HID) and coin2 is button 20. I can't get it to work. Any ideas?
« Last Edit: September 17, 2022, 06:28:05 pm by spisi »

Tiberius

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 46
  • Last login:March 03, 2024, 02:10:01 pm
  • Spent more time fixing than playing
Re: Auto Hot Key script
« Reply #15 on: September 18, 2022, 03:03:21 am »
Just to check, you still have the numbers 5 and 6 registered in Mame as your coin buttons? So you want when you press joystick button 17 or 20 to pretend to be keyboard numbers 5 or 6.

Try changing Joy17 to 1Joy17, that assumes it is the first joystick attached to system, and if that doesn't work keep changing the number one at a time until it does work, then do the same for other button.

You could try the Joystick test script to help figure out joystick number and button number

https://lexikos.github.io/v2/docs/scripts/index.htm#JoystickTest

Scroll down the page a bit and find the correct script for checking joysticks.

Good luck

Ps just checked this on mine and it work

In Mame coin input must be 5 and 6 from keyboard NOT your joystick buttons
 
Script needs to be as below - but with YOUR joystick button numbers and whatever other changes you want/need to make

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

key5 := 0
key6 := 0

~esc::
key5 := 0
key6 := 0
return

1joy9::
key5++
if key5 <= 5
{
Send {5 down}
Sleep, 50
Send {5 up}
}
return

7joy9::
key6++
if key6 <= 5
{
Send {6 down}
Sleep, 50
Send {6 up}
}
return
« Last Edit: September 18, 2022, 04:18:05 am by Tiberius »
Using Wiimotes, Demulshooter and Touchmote as lightguns......does actually work!!!

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #16 on: September 18, 2022, 09:03:25 am »
Thank you very much Tiberius. I will test out later tonight!  :applaud:

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #17 on: September 18, 2022, 10:06:10 am »
Did a quick test before I have to leave this morning. I don't think the test is picking up my "joystick". I'm using a U-HID. When I press the buttons nothing happens.
« Last Edit: September 18, 2022, 09:48:08 pm by spisi »

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #18 on: September 18, 2022, 09:50:22 pm »
My bad....it works!  It sees the buttons just as windows does...I must have had something screwy this morning...I was rushing...I love it! Now getting the points banners that show up on the road in Super Sprint actually mean something!!!  :laugh2:  Thanks again guys Abispac and Tiberius!!!

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #19 on: September 19, 2022, 12:57:59 pm »

OK one last question I promise.

I want to disable my menu button (Tab) during boot up. So that the kids don't get in there and mess stuff up.
Here's my current script:


#SingleInstance Ignore

Tab := 0

~m::             ;hold m key
Sleep 4000     ;for 4 seconds
send {m up}
Tab := 0
{
MsgBox Menu is now available!
ExitApp
}
return

Tab::
Send {}       ;disabled
return


The problem I'm having is that if I press the "m" key and let go, 4 seconds later the message pops up that my menu is available.  This is more like "press and wait" I'm looking for "press and hold". How do I tell AHK that I am pressing and holding a key for 4 seconds?

Tiberius

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 46
  • Last login:March 03, 2024, 02:10:01 pm
  • Spent more time fixing than playing
Re: Auto Hot Key script
« Reply #20 on: September 19, 2022, 03:25:42 pm »
The following stops TAB working.

You press and HOLD m for 4 seconds and then you get the pop up box. Once you manually close the pop up box TAB will work again.

If you press m or press and hold m for less than 4 seconds tab still doesn't work but also the letter m DOESN'T work


Code: [Select]
Tab := 0

m::
{
keywait, m, t4
if errorlevel = 1
{
MsgBox Menu is now available!
ExitApp
}
else
return
}

Tab::return

IF you want m to also be the letter m you need to put ~m ::

Using Wiimotes, Demulshooter and Touchmote as lightguns......does actually work!!!

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #21 on: September 20, 2022, 12:04:24 am »
Great thanks Tiberius!

spisi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 240
  • Last login:May 07, 2024, 09:47:58 am
  • I want to build my own arcade controls!
Re: Auto Hot Key script
« Reply #22 on: November 09, 2022, 10:05:51 am »
OK, having trouble with this code. I'm attempting to use a button instead of a key on a keyboard.

#SingleInstance Force


Tab := 0                                       ;disable Tab

2joy12::                               
{
keywait, 2joy12, t4                       ;hold menu button for 4 secs
if errorlevel = 1                                                                       
{             
SoundBeep, 500, 250 
ExitApp                               
}
else                                   
return                               
}

Tab::return                                   ;tab is back in business

I'm trying to get it to where instead of pressing the menu button (2joy12) to open up the menu, you have to hold it for four seconds, and then it opens the menu.
I have 2joy12 mapped to "Tab" in antimicro. I have Tab set in MAME to "config menu".
« Last Edit: November 09, 2022, 10:12:36 am by spisi »

Tiberius

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 46
  • Last login:March 03, 2024, 02:10:01 pm
  • Spent more time fixing than playing
Re: Auto Hot Key script
« Reply #23 on: November 12, 2022, 07:08:34 am »
At the moment your sripts disables Tab from working

After you press and hold joy button 12 for 4 seconds it plays a little noise for 1/4 of a second and then closes the ahk

At this point the Tab button should start working

So I expect the following behaviour at the moment when the ahk is running

Press Tab on keyboard = Nothing happens
Press Joy 12 button = Nothing happens
Press and hold Joy 12 button for less than 4 seconds = Nothing happens
Press and hold Joy 12 for 4 seconds or more = A small sound plays for 1/4 of a second the ahk closes and now Tab and Joy 12 work

Once the ahk closes (ie you have held for more than 4 seconds)
Press Tab on keyboard = Menu opens
Press Joy 12 button = Menu opens

I THINK what you want is (when the ahk is running)
Press Tab on keyboard = Nothing happens
Press Joy 12 button = Nothing happens
Press and hold Joy 12 button for less than 4 seconds = Nothing happens
Press and hold Joy 12 for 4 seconds or more = A small sound plays for 1/4 of a second the menu screen opens

BUT do you now want Tab and Joy Button 12 to work just when pressed or do you want to still have to press and hold Joy 12 for 4 seconds to do anything (eg close menu?)

I think from memory you have to press Tab again to close the menu in Mame?
Using Wiimotes, Demulshooter and Touchmote as lightguns......does actually work!!!