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: [SOLVED] AHK advice needed - Using shift to produce two keys per button  (Read 2157 times)

0 Members and 1 Guest are viewing this topic.

stigzler

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:March 21, 2025, 06:36:05 am
  • It seemed like a good idea at the time....
    • Mago Arcade
Bottom of first post is the original problem. Thought I'd cut to the chase and post the solution up here!!!!

Scenario: You want a button on your keyboard/controller/ipac etc to act as a shift key when used in combo with another button, produces a third button. For example, holding down "#" and pressing f produces "Alt+Ent."

My scenario: Have 8 'function' buttons on my cab which map to various keys via a keyboard hack - e.g. "]" + "h" + ";"  Wanted to be able to press the 2P button (mapped to 2 on minipac) to act as shift to send different keys to emulators. For instance want to send "p" from holding down "2" and pressing ";" (for pause).

The problem:

1) I don't know the technicalities, but many emulators use different methods of 'getting' keys in their menus. Lots will register the first key you press. For example, in example above, when it says "press key now" you'll hold down the 2 to press the ";" but 2 will register as first key pressed (this applies to the advanced emulator config remap in GameEx)

2) Because of key repeat, you might end up with repeated "p"s being sent resulting in successive pause,unpause,pause etc...

3) In Auto Hot Key - one method will work with one emulator and another with another (something to to with Direct send + sendkeys method or something) - therefore, one size won't fit all.

These Scripts:

a) When first press down key that will be shift - doesn't send the key (e.g. pressing 2 doesn't send 2 on key down)

[B)] If you release key without selecting another, you get "2". You can also disable this.

c) You can set it so that the shifted sent key (e.g. "p" in the example above) does not repeat - vital if have function buttons.

d) can also set the buttons that you use with the 'shift' key to also not repeat when pressed on their own (again, for function buttons this can be useful)

e) You can set the shift key to either work like a shift key (that is you can shift several keys one after the other without letting go of the shift key) or you can require that the shift key is released before accepting another function.

Solution:

1) Download AutoHotkey

2) Copy the two scripts below, paste into notepad (I'd recc "Notepad++"). Save them as "Method A" and "Method B" in your GameEx directory under created folder "AHKs and scripts" or something like that.

Method A:

Code: [Select]
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; >> Shifted Function Buttons by Stigzler
; >> Method A - Use before Method B. To "enable" a line - just delete the ";" Don't delete ; lines with >> in!
; >> Obviously, change the keys to your own!
; >> --------Fx--------------- <- name of the function button on cab, not the F keys on keyboard
; >> See F2 for example
; >> See F1 for how it works

;>>Optional enables:
;#InstallKeybdHook
;>>Change below if 'Event' not working. Options: Event,Input,Play,InputThenPlay
SendMode Event


;------------------------2 - Shift Key -----------------------------
;>>2 is essentially the shift key. If you are wanting to use 2 in emu, then enable below. Enabling first line means 2 wont register on keydown, but sends 2 on key up. Try without first line enabled first
;2::return
2 up::Send 2
;KeyWait, 2
return

;------------------------F1 + example----------------------------
$Esc:: ; >>This is the 'hotkey' i.e. the key you press on the keyboard/controller
;>>The dollar there b/c sent key (below) = the hotkey (above) and $ stops infinite loop
Send {Esc} ; sends Escape
;>>Line below stops key repeating - i.e. waits until key is released
KeyWait, Esc
return

2 & Esc:: ; >> This is a combo Hotkey - the & specifies both keys pressed together
Send {NumpadDiv}
;>>Below stops NumberDiv sent key repeating. If take out second ; you have to release 2 before using it again to shift. As is - it acts like a normal shift key
KeyWait, Esc
;KeyWait, 2
return

;------------------------F2----------------------------
; Example - pressing [ on own sends a non repeating Shift+Space.
; Pressing 2 and [ Sends non-repeating NumPad0
; Comment out "KeyWait, [" to make sent key repeat (Shift and space in this e.g.)
; Enable "KeyWait, [" to stop sent key repeating.
; Comment out "KeyWait, 2" to make 2 act like a normal shift key
; Enable "KeyWait, 2" to require user to release 2 and press it down again to do a subsequent shift function

$[::
;>>below sends shift and space
Send {Shift down} ; Press down the shift key.
Send {Space} ; Send Space
Send {Shift up} ; Release Shift key
KeyWait, [
return
2 & [::
Send {Numpad0}
KeyWait, [
;KeyWait, 2
return

;------------------------F3----------------------------
$,::
; >> If your sent key = your 'hotkey' (key specified in line above) you have to prefix it with hash
Send, `,
KeyWait, `,
return
2 & ,::
Send {Numpad6}
KeyWait, `,
;KeyWait, 2
return

;------------------------FA----------------------------
$y::
Send y
KeyWait, y
return
2 & y::
Send {Numpad7}
KeyWait, y
;KeyWait, 2
return

;------------------------FB----------------------------
$u::
Send u
KeyWait, u
return
2 & u::
Send {Numpad8}
KeyWait, u
;KeyWait, 2
return

;------------------------F4----------------------------
$]::
Send ]
KeyWait, ]
return
2 & ]::
Send {Numpad9}
KeyWait, ]
;KeyWait, 2
return

;------------------------F5----------------------------
$h::
Send h
KeyWait, h
return
2 & h::
Send {NumpadAdd}
KeyWait, h
;KeyWait, 2
return

;------------------------F6----------------------------
$`;::
Send #;
KeyWait, `;
return
2 & `;::
Send {NumpadSub}
KeyWait, `;
;KeyWait, 2
return

Method B:

Code: [Select]
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; >> Shifted Function Buttons by Stigzler
; >> Method B - Use if Method A not working. To "enable" a line - just delete the ";"
; >> Obviously, change the keys to your own!
; >> --------Fx--------------- <- name of the function key on cab, not the F keys!
; >> See ---------- F2 ----------------- for example

#InstallKeybdHook
;>>Change below if 'Event' not working. Options: Event,Input,Play,InputThenPlay
SendMode Event

;------------------------2 - Shift Key -----------------------------
;>>2 is essentially the shift key. If you are wanting to use 2 in emu, then enable below. Enabling first line means 2 wont register on keydown, but sends 2 on key up. Try without first line enabled first. Note: still not figured properly - will need some experimentation! I just keep 2 /as shift only - not requiring character '2' sent to emus
;2::Return
2 up::
SetKeyDelay,100,5
Send {Blind}{2 Down}
Send {Blind}{2 Up}
;Send {Blind}2
KeyWait, 2
return

;------------------------F1----------------------------

$Esc:: ; >>This is the 'hotkey' i.e. the key you press on the keyboard/controller
;>>The dollar there b/c sent key (below) = the hotkey (above) and $ stops infinite loop
SetKeyDelay,100,5
Send {Blind}{Esc DownTemp}
Send {Blind}{Esc Up}
;>>Line below stops key repeating - i.e. waits until key is released
KeyWait,Esc
return
;>>Keymapping for key 'shifted' with 2
2 & Esc::
SetKeyDelay,100,5
Send {Blind}{NumpadDiv DownTemp}
Send {Blind}{NumpadDiv Up}
;>>Stops sent NumberDiv key repeating. If take out second ; you have to release 2 before using it again to shift. As is - it acts like a normal shift key
KeyWait, Esc
;KeyWait, 2
return

;------------------------F2----------------------------
; Example - pressing [ on own sends a non repeating Shift+Space.
; Pressing 2 and [ Sends non-repeating NumPad0
; Comment out "KeyWait, [" to make sent key repeat.
; Enable "KeyWait, [" to stop sent key repeating.
; Comment out "KeyWait, 2" to make 2 act like a normal shift key
; Enable "KeyWait, 2" to require user to release 2 and press it down again to do a subsequent shift function

[::
SetKeyDelay,100,5
Send {Blind}{Shift down}
Send {Blind}{Space}
Send {Blind}{Shift up}
KeyWait, [
return
2 & [::
SetKeyDelay,100,5
Send {Blind}{Numpad0 DownTemp}
Send {Blind}{Numpad0 Up}
KeyWait, [
;KeyWait, 2
return

;------------------------F3----------------------------
$,::
SetKeyDelay,100,5
Send {Blind}{, DownTemp}
Send {Blind}{, Up}
KeyWait, `,
return
2 & ,::
SetKeyDelay,100,5
Send {Blind}{Numpad6 DownTemp}
Send {Blind}{Numpad6 Up}
KeyWait, `,
;KeyWait, 2
return

;------------------------FA----------------------------
$y::
SetKeyDelay,100,5
Send {Blind}{y DownTemp}
Send {Blind}{y Up}
KeyWait, y
return
2 & y::
SetKeyDelay,100,5
Send {Blind}{Numpad7 DownTemp}
Send {Blind}{Numpad7 Up}
KeyWait, y
;KeyWait, 2
return


;------------------------FB----------------------------
$u::
SetKeyDelay,100,5
Send {Blind}{u DownTemp}
Send {Blind}{u Up}
KeyWait, u
return
2 & u::
SetKeyDelay,100,5
Send {Blind}{Numpad8 DownTemp}
Send {Blind}{Numpad8 Up}
KeyWait, u
;KeyWait, 2
return

;------------------------F4----------------------------
$]::
SetKeyDelay,100,5
Send {Blind}{] DownTemp}
Send {Blind}{] Up}
KeyWait, ]
return
2 & ]::
SetKeyDelay,100,5
Send {Blind}{Numpad9 DownTemp}
Send {Blind}{Numpad9 Up}
KeyWait, ]
;KeyWait, 2
return

;------------------------F5----------------------------
$h::
SetKeyDelay,100,5
Send {Blind}{h DownTemp}
Send {Blind}{h Up}
KeyWait, h
return
2 & h::
SetKeyDelay,100,5
Send {Blind}{NumpadAdd DownTemp}
Send {Blind}{NumpadAdd Up}
KeyWait, h
;KeyWait, 2
return

;------------------------F6----------------------------
$`;::
SetKeyDelay,100,5
Send {Blind}{`; DownTemp}
Send {Blind}{`; Up}
KeyWait, `;
return
2 & `;::
SetKeyDelay,100,5
Send {Blind}{NumpadSub DownTemp}
Send {Blind}{NumpadSub Up}
KeyWait, `;
;KeyWait, 2
return

I'd advise getting the .ahk working with your emulator first, then exporting to an .exe. If you're using a front end, launch the .exe on emulator launch, then kill it on emulator close with the following bat:

Code: [Select]
@echo on

 set task=%1
 :: set task=%task:~1,-1%

 :: Kill Task
 TASKKILL /im %task% /f
 @exit

pass the name of your ahk .exe to the bat via quotes. E.g.

MapKill.bat "Nintendo64_map"

Hope this helps someone!


Old post/original problem:


Hi Folks. OK here's the scenario. Have 8 'function' buttons on my cab connected to a keyboard hack. They're hardwired to keys such as "[" and ";"

What I'm trying to achieve is to have two functions per function button. Have 2P Start button wired to a minipac and mapped to R Shift.

My original thinking was that I would hold this down to get the shifted character: "[" to "{" for e.g - hence giving me two buttons for the price of one!

But...

A lot of emulators, when you set keys and they say "please press key" register the "R Shift" as the button when I press R Shift and "["

What I am looking for is something to run in the background to map either "R SHift and [" or the symbol "{" into another unshifted keypress (e.g. Num Keys)

Tried:
XPadder - wierdly - seems you can only have controllers as input - no keyboard registered as an input device.
GameEx Advanced Emulator Config: Allows re-mapping of keys - but has same problem with keys registering as "R Shift"
WinPac - because F buttons wired via keyboard hack, can't access them via P1 shift system.

So, is there any software to run in the background to convert "Shift + [" input to "Num 7" output (lucky for some!).

Thanks
« Last Edit: January 06, 2014, 07:08:43 pm by stigzler »

stigzler

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:March 21, 2025, 06:36:05 am
  • It seemed like a good idea at the time....
    • Mago Arcade
Re: Convert Keyboard keypresses 'on the fly'?
« Reply #1 on: December 29, 2013, 02:34:49 pm »
Never mind, figured it myself. For those in same position that I was this morning, use this-

http://www.autohotkey.com/

And example of the script-

#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.

+[::Numpad0
+,::Numpad6
+y::Numpad7
+u::Numpad8
+]::Numpad9
+h::NumpadAdd
+;::NumpadSub
« Last Edit: December 30, 2013, 04:07:37 pm by stigzler »

stigzler

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:March 21, 2025, 06:36:05 am
  • It seemed like a good idea at the time....
    • Mago Arcade
Re: Convert Keyboard keypresses 'on the fly'? [Solved, but then not!]
« Reply #2 on: December 30, 2013, 04:05:05 pm »
Dammit! That didn't work.

For some reason, the emu I tested this in still registers the RShift Button on initial keypress.

So messed about some more. Tried-

"KeyWait, RShift" -
 still registers in emu on key down

"RShift::return
RShift up::Send RShift"
Still 'sees' R Shift

+ others (using "UP" command etc)

Is there any way for AHK to stop any application seeing Right Shift unless one of the following occur?:
- It is released without another key being pressed (i.e. send Rshift only when released) - this is my 2P button
- It is used with another key to make a hotkey (that is sends a hotkey from combo (e.g. * form RShift and [) but doesn't send the RShift after the hotkey

btw R Shift is mapped via WinIPac/minipac

getting very befuddled by all this. Test emu is Stella, but also does in WinIPac test mode.

CHeers
« Last Edit: December 30, 2013, 04:08:18 pm by stigzler »

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9272
  • Last login:July 24, 2025, 02:05:45 pm
  • ...
Re: AHK advice needed - Using shift to produce two keys per button
« Reply #3 on: December 30, 2013, 04:19:42 pm »
Some emulators get the input in a more direct way from the device, so are unaffected by windows programs like Autohotkey.
MAME falls into that category, not sure about Stella.

stigzler

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:March 21, 2025, 06:36:05 am
  • It seemed like a good idea at the time....
    • Mago Arcade
Re: AHK advice needed - Using shift to produce two keys per button
« Reply #4 on: December 30, 2013, 05:02:33 pm »
Thanks Bad,

Solved problem a bit more:

Appears as though the RShift key wouldn't work with this:
RShift::return
RShift::Send RShift

But LShift does!!!! Something shifty about RShift!

So, now remapped "P in WinPac to "2" and using this.

Works bit better - "2" not triggering Stella now on key down + provides suitable 'shifted' hotkeys. Also, registers "2" on key up.

 Script now looking like this:

2::return
2 up::Send 2
2 & [::Send {Numpad0}
2 & ,::Send {Numpad6}
2 & y::Send {Numpad7}
2 & u::Send {Numpad8}
2 & ]::Send {Numpad9}
2 & h::Send {NumpadAdd}
2 & `;::Send {NumpadSub}

However, WinIpac and Mame don't recognise 2 on key release!!

2 days on this now - doing my head in!


PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 9672
  • Last login:Today at 03:12:54 am
  • Designated spam hunter
Re: AHK advice needed - Using shift to produce two keys per button
« Reply #5 on: December 30, 2013, 05:40:39 pm »
I think the closest answer to what you are trying to do is to use a KADE/AVR encoder with a custom keymap -- Jon will probably whip one up for you if you ask him nicely.   ;D

The difference between what you described and the KADE is that unlike the IPac, the KADE doesn't have an output associated with the shift (HWB on KADE), so you'd probably need separate P2 Start and HWB buttons.   :dunno


Scott

stigzler

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:March 21, 2025, 06:36:05 am
  • It seemed like a good idea at the time....
    • Mago Arcade
Re: AHK advice needed - Using shift to produce two keys per button
« Reply #6 on: December 31, 2013, 11:07:34 am »
Thanks PL1, bur buying new hardware not really solution im looking for, espdcially when spent 2 weeks wiring up my cab with minipac and keyboard hack!

On reflection, think it boils down to this - how do you send keys to mame (and potentially other non-sendkeys conforming emulators) from autohotkey.

Surely someone here must know!

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9272
  • Last login:July 24, 2025, 02:05:45 pm
  • ...
Re: AHK advice needed - Using shift to produce two keys per button
« Reply #7 on: December 31, 2013, 11:26:40 am »
Thanks PL1, bur buying new hardware not really solution im looking for, espdcially when spent 2 weeks wiring up my cab with minipac and keyboard hack!

On reflection, think it boils down to this - how do you send keys to mame (and potentially other non-sendkeys conforming emulators) from autohotkey.

Surely someone here must know!

With MAME, you can make a simple change in the source code and compile it yourself.
It's been posted about a few times, but I don't have a link.
Some searching should turn up the appropriate line to change.

With the other emulators, you really are out of luck unless they are open source and you know what to change.


stigzler

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:March 21, 2025, 06:36:05 am
  • It seemed like a good idea at the time....
    • Mago Arcade
Re: AHK advice needed - Using shift to produce two keys per button
« Reply #9 on: January 01, 2014, 06:19:27 am »
Thanks BadMouth - found it! That'll sort for mame, but from starting to trawl my emulators, fearing may have similar probs with others (ZSNES so far is one that doesn't work with AHK).

This seems like an elementary problem - is there any other software to do similar to AHK, but send the correct inputs to Mame and other emulators?

Thanks Michel - but not sure duct taping a wireless keyboard to the front of my control panel will be a good look!