Skip to content

Instantly share code, notes, and snippets.

@Prurite
Last active September 12, 2024 02:36
Show Gist options
  • Save Prurite/496d02319e84f4f7acac7eeeafd431d8 to your computer and use it in GitHub Desktop.
Save Prurite/496d02319e84f4f7acac7eeeafd431d8 to your computer and use it in GitHub Desktop.
Switch DDG controller levels to keys
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 with key mapping
positions := Map("P5", "Numpad5", "P4", "Numpad4", "P3", "Numpad3",
"P2", "Numpad2", "P1", "Numpad1",
"N", "0", "B1", "1", "B2", "2", "B3", "3", "B4", "4",
"B5", "5", "B6", "6", "B7", "7", "B8", "8", "EB", "9")
; Initialize last position
lastPosition := "N"
; Timer to check Axis 1 position
SetTimer(CheckAxis, 100)
CheckAxis() {
global levels, positions, lastPosition, keyDelay
axis1 := GetKeyState("JoyY")
; Find the closest position
closestPos := ""
closestDist := 100 ; 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 {
SendKeys(positions[closestPos])
lastPosition := closestPos
}
}
SendKeys(key) {
global keyDelay1, keyDelay2
Send("{" . key . " down}")
Sleep(keyDelay1)
Send("{" . key . " up}")
Sleep(keyDelay2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment