Last active
August 18, 2024 11:00
-
-
Save Prurite/9d650961319a2adb0cf42db08386d8da to your computer and use it in GitHub Desktop.
Switch DDG Controller to Arrow key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Persistent | |
#SingleInstance Force | |
; Set default delay between key presses | |
keyDelay1 := 40 | |
keyDelay2 := 40 | |
; Axis 1 positions mapped to levels | |
levels := Map(100, "P5", 90, "P4", 80, "P3", 71, "P2", 61, "P1", 50, "N", | |
39, "B1", 34, "B2", 28, "B3", 23, "B4", 18, "B5", | |
12, "B6", 7, "B7", 2, "B8", 0, "EB") | |
; Reverse lookup for easy access | |
positions := Map("P5", 15, "P4", 14, "P3", 13, "P2", 12, "P1", 11, "N", 10, | |
"B1", 9, "B2", 8, "B3", 7, "B4", 6, "B5", 5, "B6", 4, "B7", 3, "B8", 2, "EB", 1) | |
; Initialize last position | |
lastPosition := "N" | |
; Timer to check Axis 1 position | |
SetTimer(CheckAxis, 100) | |
CheckAxis() { | |
global levels, positions, lastPosition, keyDelay | |
axis1 := GetKeyState("JoyY") | |
; print axis1 value for debugging | |
; MsgBox(axis1) | |
; Find the closest position | |
closestPos := "" | |
closestDist := 2 ; larger than any possible distance | |
for pos, level in levels { | |
dist := Abs(axis1 - pos) | |
if dist < closestDist { | |
closestDist := dist | |
closestPos := level | |
} | |
} | |
; Compare to last position and send key presses | |
if closestPos != lastPosition { | |
diff := positions[closestPos] - positions[lastPosition] | |
if diff > 0 { | |
SendKeys("Down", Abs(diff)) | |
} else if diff < 0 { | |
SendKeys("Up", Abs(diff)) | |
} | |
lastPosition := closestPos | |
} | |
} | |
SendKeys(key, count) { | |
global keyDelay | |
Loop count { | |
Send("{" . key . " down}") | |
Sleep(keyDelay1) | |
Send("{" . key . " up}") | |
Sleep(keyDelay2) | |
} | |
} |
Do you know which versions of DDG this'd work on?
Any version that supports arrow keys to change the gears.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know which versions of DDG this'd work on?