But it works with a timer and I want it to check as soon as i press the button
I press button 2Joy11 and I want it to start checking if i'm tilting my joystick upwards, and then do a command
But it doesnt work
Code: Select all
2Joy11::
GetKeyState, 2JoyX, 2JoyX ; Get position of X axis.
GetKeyState, 2JoyY, 2JoyY ; Get position of Y axis.
KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
if (2JoyX > 70) and GetKeyState("2Joy11")
KeyToHoldDown = D
else if (2JoyX < 30) and GetKeyState("2Joy11")
KeyToHoldDown = A
else if (2JoyY > 70) and GetKeyState("2Joy11")
KeyToHoldDown = S
else if (2JoyY < 30) and GetKeyState("2Joy11")
KeyToHoldDown = W
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 KeyToHoldDownPrev ; There is a previous key to release.
SendInput, {%KeyToHoldDownPrev% up} ; Release it.
if KeyToHoldDown ; There is a key to press down.
SendInput, {%KeyToHoldDown% down} ; Press it down.
return
; Long press (> 0.5 sec) on Esc closes window
KeyWait, 2Joy11, T7.0 ; Wait no more than 0.5 sec for key release (also suppress auto-repeat)
If ErrorLevel ; timeout, so long press
SendInput, {M down}
Sleep, 100
SendInput, {M Up}
Return