-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJoystick-Overlay.ahk
98 lines (79 loc) · 3.35 KB
/
Joystick-Overlay.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#Persistent
#NoEnv
OnExit, GuiClose
;///////////////////////////////////////////////////////////////////////////////
;Configuration
;///////////////////////////////////////////////////////////////////////////////
;Use the Joystick Test Script to find desired joyNum and axes letters.
;https://autohotkey.com/docs/scripts/JoystickTest.htm
;X Y Z R U V
joyNum := "1"
axisRoll := "X"
axisPitch := "Y"
axisYaw := "R"
axisThrust := "U"
;Set window position and title.
windowX := "100"
windowY := "100"
windowTitle := "Joystick-Overlay"
;///////////////////////////////////////////////////////////////////////////////
Gui, Show, W200 H200 X%windowX% Y%windowY%, %windowTitle%
W:=200
H:=200
SetTimer, Disp, off
DllCall("DeleteObject", "UInt", hPen)
DllCall("DeleteObject", "UInt", hPen2)
hPen := DllCall("CreatePen", "UInt", 0, "UInt", 1, "UInt", 0xffccff) ;background
hPen2 := DllCall("CreatePen", "UInt", 0, "UInt", 0, "UInt", 0) ;axes and cursors
hBrush := DllCall("CreateSolidBrush", "UInt", 0xffccff, "Ptr") ;background
DllCall("ReleaseDC", "UInt", htx, "UInt", hdcMem)
hdcWin := DllCall("GetDC", "UPtr", hwnd:=WinExist(windowTitle))
hdcMem := DllCall("CreateCompatibleDC", "UPtr", hdcWin, "UPtr")
hbm := DllCall("CreateCompatibleBitmap", "UPtr", hdcWin, "int", W, "int", H, "UPtr")
hbmO := DllCall("SelectObject", "uint", hdcMem, "uint", hbm)
DllCall("SetROP2", "UInt", hdcMem, "UInt", 0x04) ;hex for SRCOPY mix mode
;update rate ~60Hz
SetTimer, Disp, 16
return
;draw and update loop
Disp:
;draw rect to wipe
DllCall("SelectObject", "UInt", hdcMem, "UInt", hPen) ;select pen
DllCall("SelectObject", "UInt", hdcMem, "UInt", hBrush) ;select brush
DllCall("Rectangle", "UInt", hdcMem, "int", 0 , "int", 0, "int", W, "int", H)
;draw referece
DllCall("SelectObject", "uint", hdcMem, "uint", hPen2)
DllCall("MoveToEx", "UInt", hdcMem, "int", 0, "int", 99, "UInt", NULL)
DllCall("LineTo", "UInt", hdcMem, "int", W, "int", 99)
DllCall("MoveToEx", "UInt", hdcMem, "int", 99, "int", 0, "UInt", NULL)
DllCall("LineTo", "UInt", hdcMem, "int", 99, "int", H)
;read axes
x := GetKeyState(joyNum "Joy" axisRoll) * 2
y := GetKeyState(joyNum "Joy" axisPitch) * 2
r := GetKeyState(joyNum "Joy" axisYaw) * 2
u := GetKeyState(joyNum "Joy" axisThrust) * 2
;draw pitch/roll
DllCall("MoveToEx", "UInt", hdcMem, "int", x-4, "int", y, "UInt", NULL)
DllCall("LineTo", "UInt", hdcMem, "int", x+5, "int", y)
DllCall("MoveToEx", "UInt", hdcMem, "int", x, "int", y-4, "UInt", NULL)
DllCall("LineTo", "UInt", hdcMem, "int", x, "int", y+5)
;draw yaw
DllCall("MoveToEx", "UInt", hdcMem, "int", r, "int", H-6, "UInt", NULL)
DllCall("LineTo", "UInt", hdcMem, "int", r, "int", H)
;draw thrust
DllCall("MoveToEx", "UInt", hdcMem, "int", W-6, "int", u, "UInt", NULL)
DllCall("LineTo", "UInt", hdcMem, "int", W, "int", u)
;update screen
DllCall("BitBlt", "uint", hdcWin, "int", 0, "int", 0, "int", W, "int", H, "uint", hdcMem, "int", 0, "int", 0, "uint", 0xCC0020) ;hex code for SRCOPY raster-op code
return
ExitSub:
GuiClose:
DllCall("DeleteObject", "Ptr", hPen)
DllCall("DeleteObject", "Ptr", hPen2)
DllCall("DeleteObject", "Ptr", hBrush)
DllCall("DeleteObject", "Ptr", hbm)
DllCall("DeleteObject", "Ptr", hbmO)
DllCall("DeleteDC", "Ptr", hdcMem)
DllCall("ReleaseDC", "Ptr", hwnd, "UInt", hdcWin)
ExitApp