Jump to content

All my products and services are free. All my costs are met by donations I receive from my users. If you enjoy using any of my products, please donate to support me. Thank you for your support. Tom Speirs

Patreon

[GUIDE] AHK and mapping button as a shift button to double your keys!


Recommended Posts

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:

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

#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

3) Get controls working outside of GameEx first. For now, just click on the MethodA.ahk. You'll see an icon in your tray at bottom right. Change the keys therein to match your own (just try one or two to start - a 'shifted' and 'unshifted' function). Test in notepad fisrt to ensure some key mapping. Then test in your emulator. If Method A works, goto (5)

4) If you can't get Method A working... try Method B!! Same drill - setup couple of trial keys - try in emulator etc.. Once working...

5) Save your working script. Right click on the AHK file and select "Compile Script" - it'll produce an .exe - save this somewhere, but keep the AHK in case you need to edit in the future.

6) Set up GameEx to start the AHK script on emulator launch and to kill it on emulator close. To do so:

7) Create the following .bat file (cut, paste to notepad, save with .bat extension), which will kill any specified running process in task manager:

@echo on

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

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

8) Go into Plugin manager and the QuickLaunch plugin.

9) Select your Emulator and then "Add"

10) Make up a name in "Process name"

11) Select your AHK exe in process exe

12) No arguments (!)

13) Select "Launch Before" then Save. (this will launch your AHK script when Emulator loads)

14) In same Emulator, create another to kill the process, but this time:

- Select the bat file you just created as the exe (you can change the viewed file types in the file select menu)

- In the Arguments section put the name of your AHK exe surrounded by quotes. E.g.:

"Nintendo64_remap.exe."

15) Select "Launch After"

You should get something like this (my filenames obviously different)

ahk.png

And that's it!

I'll update below emulators I've tested this on, the relevant Method and anything noteworthy. Hope this saves someone a bit of time, coz it was a bit of a trial sorting this!

Emulators and configs:

DesMume (Nintendo DS) - Method B

Cannot configure Alt+Enter in menu - do via remap of a hotkey to Alt+Enter.

Demul (0.5.8.2) (Dreamcast+Atomiswave+Naomi) - Method B

required manual mappings (can't config in menu or .ini - do in AHK script)

Pause key - Pause

F6 - Aspect Ratio

F5 - Rotation

F9 (??) - read somewhere that this is screenshot but can't get this working at all!

Can't find hotkey guide for this anywhere

VisualBoy Advance (Gameboy Advance) - Method A

ProSystem (Atari 7800) - Method A

Manual remaps:

Ctrl+R - Reset ("^r" in AHK)

Ctrl+L - Load

CTRL+P - Pause

Virtual Jaguar (Atari Jaguar) - Method A

OK.. bored of this bit now... drop a reply if you need any more of these! Strictly an on demand service. :)

  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...