This timer will save you much hassle if you intend to control a WASD game with a joystick, it even handles diagonals!
Code: Select all
;Perfect WASD by Fodakahn
#Persistent
SetTimer, joystick, 1
joystick:
getkeystate, 1JoyX, 1JoyX
getKeystate, 1JoyY, 1JoyY
if (1JoyX > 40) and (1JoyX < 60) and (1JoyY > 40) and (1JoyY < 60) ;centered
{
if GetKeyState("A")
Send {A up}
if GetKeyState("D")
Send {D up}
if GetKeyState("W")
Send {W up}
if GetKeyState("S")
Send {S up}
}
else if (1JoyX < 40) and (1JoyY > 60) ;down-left
{
if GetKeyState("D")
Send {D up}
if GetKeyState("W")
Send {W up}
if !(GetKeyState("S"))
Send {S down}
if !(GetKeyState("A"))
Send {A down}
}
else if (1JoyX < 40) and (1JoyY < 40) ;up-left
{
if GetKeyState("D")
Send {D up}
if GetKeyState("S")
Send {S up}
if !(GetKeyState("W"))
Send {W down}
if !(GetKeyState("A"))
Send {A down}
}
else if (1JoyX > 60) and (1JoyY < 40) ;up-right
{
if GetKeyState("A")
Send {A up}
if GetKeyState("S")
Send {S up}
if !(GetKeyState("W"))
Send {W down}
if !(GetKeyState("D"))
Send {D down}
}
else if (1JoyX > 60) and (1JoyY > 60) ;down-right
{
if GetKeyState("A")
Send {A up}
if GetKeyState("W")
Send {W up}
if !(GetKeyState("S"))
Send {S down}
if !(GetKeyState("D"))
Send {D down}
}
else if (1JoyX < 25) and (1JoyY > 40) and (1JoyY < 60) ;left
{
if GetKeyState("D")
Send {D up}
if GetKeyState("W")
Send {W up}
if GetKeyState("S")
Send {S up}
if !(GetKeyState("A"))
Send {A down}
}
else if (1JoyX > 75) and (1JoyY > 40) and (1JoyY < 60) ;right
{
if GetKeyState("A")
Send {A up}
if GetKeyState("W")
Send {W up}
if GetKeyState("S")
Send {S up}
if !(GetKeyState("D"))
Send {D down}
}
else if (1JoyY > 75) and (1JoyX > 40) and (1JoyX < 60) ;down
{
if GetKeyState("A")
Send {A up}
if GetKeyState("D")
Send {D up}
if GetKeyState("W")
Send {W up}
if !(GetKeyState("S"))
Send {S down}
}
else if (1JoyY < 25) and (1JoyX > 40) and (1JoyX < 60) ; up
{
if GetKeyState("A")
Send {A up}
if GetKeyState("D")
Send {D up}
if GetKeyState("S")
Send {S up}
if !(GetKeyState("W"))
Send {W down}
}
return