Script not working in game

Ask gaming related questions
09tir98
Posts: 1
Joined: 08 Oct 2019, 11:14

Script not working in game

08 Oct 2019, 11:20

Hello!
I'm trying to make a H-Shifter for Euro Truck 2/ American Truck with an old joystick.
I've set it up so that top left is numpad 1, bottom left is numpad 2 etc. It works as long as I'm not in the game. When I'm in the game it only works once, then I have to alt+tab out of the game and then go back in for it to work once again. I have to do this every time I change gear. Does anyone know what's wrong? Here's my code:

Code: Select all

#Persistent

JoystickNumber = 4

SetTimer, WatchAxis, 5
return

WatchAxis:
	GetKeyState, JoyX, %JoystickNumber%JoyX
	joy_x = %JoyX%
	GetKeyState, JoyY, %JoystickNumber%JoyY
	joy_y = %JoyY%
KeyToHoldDownPrev = KeyToHoldDown  ; Prev now holds the key that was down before (if any).

if (joy_x < 20) && (joy_y < 20){
    KeyToHoldDown := "Numpad1"
}

else if (joy_x < 20) && (joy_y > 80){
    KeyToHoldDown := "Numpad2"
}

else if (joy_y < 20) && (joy_x < 60) && (40 < joy_x){
    KeyToHoldDown := "Numpad3"
}

else if (joy_y > 80) && (joy_x < 60) && (40 < joy_x){
    KeyToHoldDown := "Numpad4"
}

else if (joy_y < 20) && (joy_x > 80){
    KeyToHoldDown := "Numpad5"
}

else if (joy_y > 80) && (joy_x > 80){
    KeyToHoldDown := "Numpad6"
}

else {
     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 -1  ; Avoid delays between keystrokes.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return

Return to “Gaming”

Who is online

Users browsing this forum: kjaty and 32 guests