Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Conditional Function Keys


  • Please log in to reply
6 replies to this topic
BWareFL
  • Guests
  • Last active:
  • Joined: --
I'm new to AutoHotKey, and also to programming itself. I have some basic understanding, so I've been able to tinker around with this a bit for a project I'm working on, but I've run into a few problems that I'm hoping the community here can help me with.

I'm using a keyboard hack with two hardware buttons that trigger F2 and F3, respectively. It would be nice if all the game console emulators out there would be a bit more flexible (or standard) with their key assignments, but they just aren't. I'm trying to find a workaround, using AHK, that will allow F2 and F3 to perform the same functions in these emulators (save state/load state).

Here's the code I've come up with so far...
SetTitleMatchMode 2
SetKeyDelay, 1, 2, Play
SetWinDelay, 0
#InstallKeybdHook

;VisualBoy Advance -- Works!
#IfWinExist, VisualBoyAdvance
F2::SendPlay {F5}
F3::SendPlay {F7}
return

;KGen -- Works!
#IfWinExist, Fusion
F2::SendPlay {F5}
F3::SendPlay {F8}
return

;MAME -- Nothing.
#IfWinExist, MAME
F2::SendPlay {F5}1
F3::SendPlay {F7}1
return

;Project64 -- Works!
#IfWinExist, Project64
F2::SendPlay {F5}
F3::SendPlay {F7}
return

;FCE Ultra -- Nothing.
#IfWinExist, FCE Ultra
F2::SendPlay {F5}
F3::SendPlay {F7}
return

;pSX Emulator -- Strangely, F3 works while F2 doesn't.
#IfWinExist, pSX
F2::SendPlay {F10}
F3::SendPlay {F5}
return

;ZSNES -- Nothing.
#IfWinExist, ahk_class ZSNES
F2::SendPlay {F5}
F3::SendPlay {F7}
return
I've tried a number of different approaches, and this is the most successful so far.

What could the problem be? I can confirm that the windows are being properly recognized, as the previous functions assigned by the emulator are blocked out when the program is running. The problem must lie in how the commands are being sent....

The emulators marked with "Works!" work absolutely perfectly. The others just don't respond in any way.

Any ideas?


*Note on the MAME emulator: When the savestate or loadstate buttons are pressed, they must be followed by a second keystroke indicating a slot.

Democratus
  • Members
  • 120 posts
  • Last active: Dec 02 2008 08:21 AM
  • Joined: 01 Sep 2007
This obviously won't work for MAME, but for the other emulators have you tried replacing the hotkey values directly? For example,

F2::F5
F3::F7

I have found that this is often much more reliable than any other method (It's the only way I could get my hotkeys working in Warcraft).

Good luck.

  • Guests
  • Last active:
  • Joined: --
Thanks for the response. Is there really no way for this to work in MAME? It wouldn't be the end of the world if I couldn't get the savestates in MAME to run, but it would be nice. Is there any particular reason why a macro wouldn't work in this case?

Thanks for the help- I'll give your suggestion a try!

Democratus
  • Members
  • 120 posts
  • Last active: Dec 02 2008 08:21 AM
  • Joined: 01 Sep 2007
The initial part would, but the second part in which you must send the slot wouldn't. So, you could remap the F2 and F3 keys to the save/load function but you would have to enter in the slot value yourself.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
#IfWinExist, MAME
F2::SendEvent {F5}1
F3::SendEvent {F7}1
Have you tried SendEvent ?

BWareFL
  • Guests
  • Last active:
  • Joined: --
Hmm...no, I haven't tried SendEvent. I'll have to give that a shot as well.

But about the MAME macro, why wouldn't a second keystroke for 1 (ie, selecting the slot) work? If the initial function key does, I don't see why 1 wouldn't.


Thanks again for the help!

BWareFL
  • Guests
  • Last active:
  • Joined: --
UPDATE:
The direct F2:F5 remapping worked like a charm. It's amazing that I didn't try that to begin with!

For the MAME emulator, I'm going to also have the two hardware buttons short the 1 key. It will require 2 clicks, but this will allow the savestates to work with MAME.

Thanks again for the help!