gists/360_wasd/360-stick.ahk
2018-10-11 16:45:29 +02:00

64 lines
No EOL
873 B
AutoHotkey

#Persistent
#SingleInstance Force
Send {w up}
Send {a up}
Send {s up}
Send {d up}
Deadzone := 0.6
SetTimer Wax, 5
return
Wax:
GetKeyState JoyX, JoyX
GetKeyState JoyY, JoyY
JoyX := (JoyX - 50)/50
JoyY := (JoyY - 50)/50
Angle := ATan(JoyX/JoyY)*2/3.14159
Angle := (JoyY > 0) ? Angle + 3: Angle + 1
Length := Sqrt(JoyX**2 + JoyY**2)
; 1 1 0
; 2 - 0
; 2 3 3
OldX = %HoldX%
OldY = %HoldY%
if Length > %Deadzone%
{
if % Angle >= 1.2 && Angle < 2.7
HoldX = a
else if % Angle >= 3.2 || Angle < 0.7
HoldX = d
else
HoldX =
if % Angle >= 0.3 && Angle < 1.7
HoldY = w
else if % Angle >= 2.3 && Angle < 3.7
HoldY = s
else
HoldY =
} else
{
HoldX =
HoldY =
}
SetKeyDelay -1
if OldX != %HoldX%
{
if HoldX
Send {%HoldX% down}
if OldX
Send {%OldX% up}
}
if OldY != %HoldY%
{
if HoldY
Send {%HoldY% down}
if OldY
Send {%OldY% up}
}
return
F10::ExitApp