Remap Joystick Hat to Send Multiple Arrow Keys

Ask gaming related questions (AHK v1.1 and older)
Panopticon86
Posts: 3
Joined: 27 Aug 2019, 13:02

Remap Joystick Hat to Send Multiple Arrow Keys

26 Nov 2021, 15:31

Greetings friends!

I am trying to remap my joystick hat to send multiple arrow key presses based on its current position. I want it to hit a key only once (regardless of how long I hold it down), wait a short duration (maybe 100 ms), then hit another key.

Fifth attempt: this is a bad workaround that gets some of the functionality I want but it continues to loop the Up press if I hold down the hat left or right too long. Unfortunately, the KeyWait function doesn't work with non-button aspects of joysticks or I could time it to the position of the hat itself.

Code: Select all

#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchPOV, 5
return

WatchPOV:
POV := GetKeyState("JoyPOV")  ; Get position of the POV control.
KeyToHoldDownPrev := KeyToHoldDown  ; Prev now holds the key that was down before (if any).

if POV between 4501 and 13500  ; Right
{
   SendInput {Up down}
   Sleep 150
   SendInput {Up up}
   KeyToHoldDown := "Right"
}
else if POV between 22500 and 31500 ; Left
{ 
   SendInput {Up down}
   Sleep 150
   SendInput {Up up}
   KeyToHoldDown := "Left"
}
else if (POV > 13500) && (POV < 22500)
{ 
   KeyToHoldDown := ""
}
else if (POV < 0)
{ 
   KeyToHoldDown := ""
}

if (KeyToHoldDown = KeyToHoldDownPrev)  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay 0  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Remap Joystick Hat to Send Multiple Arrow Keys

28 Nov 2021, 07:09

I cannot test this, but the things I would try first would be to eliminate your key delay command, and change your timer frequency to 250. If the script works at that point, you have a starting point from which to adjust it. You could even first eliminate your timer, and see if a single iteration, or just 2-3 iterations, provide the intended effect. I would also check the values of your variables along the way. You can display them so that you understand what they are.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 77 guests