Created
September 25, 2024 13:38
-
-
Save Prurite/0420d90ef63e523a7d69baacfd2d898b to your computer and use it in GitHub Desktop.
Script that converts Sanying train controller input to key press for Teknoparrot.
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 a timer to check joystick input every 60ms | |
SetTimer(CheckJoystickInput, 80) | |
lastKey := "" | |
CheckJoystickInput() { | |
; Read the joystick buttons (assuming you have a joystick connected) | |
joystick6 := GetKeyState("Joy7") | |
joystick7 := GetKeyState("Joy8") | |
joystick8 := GetKeyState("Joy9") | |
joystick9 := GetKeyState("Joy10") | |
global lastKey | |
; Default key to press (empty initially) | |
keyToPress := "" | |
; Determine the combination of pressed buttons | |
if (joystick6 && joystick7 && joystick8 && joystick9) { | |
keyToPress := "Numpad5" | |
} else if (joystick6 && joystick7 && joystick8) { | |
keyToPress := "Numpad4" | |
} else if (joystick6 && joystick7 && joystick9) { | |
keyToPress := "Numpad3" | |
} else if (joystick6 && joystick7) { | |
keyToPress := "Numpad2" | |
} else if (joystick6 && joystick8 && joystick9) { | |
keyToPress := "Numpad1" | |
} else if (joystick6 && joystick8) { | |
keyToPress := "0" | |
} else if (joystick9 && joystick6) { | |
keyToPress := "1" | |
} else if (joystick6) { | |
keyToPress := "2" | |
} else if (joystick9 && joystick8 && joystick7) { | |
keyToPress := "3" | |
} else if (joystick8 && joystick7) { | |
keyToPress := "4" | |
} else if (joystick7 && joystick9) { | |
keyToPress := "5" | |
} else if (joystick7) { | |
keyToPress := "6" | |
} else if (joystick8 && joystick9) { | |
keyToPress := "7" | |
} else if (joystick8) { | |
keyToPress := "8" | |
} else if (joystick9) { | |
keyToPress := "9" | |
} | |
; If a key is determined, send it | |
if keyToPress != lastKey { | |
Send("{" . keyToPress . " down}") ; Send the key press based on joystick combination | |
lastKey := keyToPress | |
Sleep(40) | |
Send("{" . keyToPress . " up}") | |
Sleep(40) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment