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