Thursday, April 16, 2009

Autohotkey

You makin a MAME case?  Are you?

Then frelling well get this: http://www.autohotkey.com/

Why you ask?  Its a program, sorry, FREE program that allows you to rebind keys basically.  For starters.  Theres a lot more it can do.

I got it for the trouble I had with WinVICE:  To exit, you required Ctrl-x.  Not very cab-friendly, as dammit I wanna use ESC to exit thanks.

Autohotkey comes in here, and delivers in spades.  (Not only that, spades are trump this trick too...)

I made two files as follows:
Code: autoexit.ahk

#singleinstance ignore ;Once program running, dont run twice
esc::!x ;Bind ESC :to: Ctrl-X (!=ctrl)
p::!j ;Bind P :to: Ctrl-J (!=Ctrl)

Line #1 So this program would only run once (if run again the program exits due to the first line)
Line #2When ESC is pushed, it parses Ctrl-X to windows instad. (So now, I can exit this emulator with ESC, which is standard with all other emulators I have)
Line #3When P is pushed, it parses Ctrl-J (Ctrl-J swaps C64 joysticks, as some games use joy#2 as main controller)

So how does a *.ahk file help me with programs like MAMEWAH?????
Autohotkey also enters itslef into windows right-click menu.  So right clicking on a ahk file allows you to compile to exe.  Do that, and you have a EXE file that will function exactly the same.

Fantastic.. buut if i Exit and go to another program, ESC is still Ctrl-X...

So I wrote this to fix that:
Code: autoexite.ahk
#singleinstance ignore
DetectHiddenWindows On  ; Allows a script's hidden main window to be detected.
SetTitleMatchMode 2  ; Avoids the need to specify the full path of the file below.
WinClose escexit.exe  ; Update this to reflect the script's name (case sensitive).
Alright, so what this script does is basically find the PID of the original program we ran, and nukes it.  change the 'escexit.exe' to the name of your program and volia!

Hows that help?  Run the first program before your emulator, run the second one after it.  Most frontends should do this, the following is how I did it in my MAMEWAH script:
CODE: WinVICE.bat
start escexit.exe
x64.exe -fullscreen -VICIIdsize +confirmexit -autostart %1
escexite.exe

START is a DOS command that runs the .exe and returns control to the batch file. (Without it, the batch file waits for escexit to finish, which it doesnt until its forcably exited by escexite.exe.  Net result is the batch hangs and never executes x64.exe)
xt64 command line: -fullscreen starts in fullscrenn, -VICIIdsize I found required to get it FULL fulscreen +confirmexit removes the annoying messagebox "DO YOU WANT TO EXIT Y/N", and -autostart runs the file parsed to it.  %1 of course is replaced with the argument that is passed to the batch file.

So my WINVICE.INI looks like:

...
emulator_commandline                      d:\emulators\WinVICE\winvice.bat "[rompath]\[name].[romext]"{nodosbox}
...

Alright, so yay sausages!  Who cares you moron, you can program the IPAC to different keybinds for each file!

Yes you can.  I decided not to, beacuse of the following points:
  • Customizable keys must be stored in flash memory.  Flash memory has a limited number of write cycles.  IPACS are not cheap. (Yes, i know it has millions of write cycles, im a perfectionist)
  • If interupted during repogramming, you end up with the old control set.
  • I read that it takes a few seconds to get it programmed, and if controls are slammed around the programming is interuppted, and the above point happens.
  • Drunk twenty-somethings (and the odd thirty-something) tend to get excited about nostalgia, and wont be patient when they get a arcade joystick in their dorito-stained hands.
  • Sitting a program in between the keyboard port and the software keyboard queue is quite neat.
  • I need this functionality for DOS programs like COMMANDER KEEN, QUAKE and DOOM, where I can run a AHK file per-game (To bind letters like Y for confirm exit to a spare button).  Might as well get used to it.

No comments:

Post a Comment