-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJoystick.Demo.ahk
187 lines (163 loc) · 5.34 KB
/
Joystick.Demo.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
; REQUIRES AHK >= v1.1.20.00
#include CHID.ahk
#singleinstance force
SetBatchLines -1
OutputDebug, DBGVIEWCLEAR
jt := new JoystickTester()
return
class JoystickTester extends CHID {
GUI_WIDTH := 661
__New(){
base.__New()
Gui, Add, Text, % "xm Center w" this.GUI_WIDTH, % "Select a Joystick to subscribe to WM_INPUT messages for that UsagePage/Usage."
Gui, Add, Listview, % "hwndhLV w" this.GUI_WIDTH " h150 +AltSubmit +Grid",Handle|GUID|Name|Btns|Axes|POVs|VID|PID|UsPage|Usage
this.hLV := hLV
LV_Modifycol(1,50)
LV_Modifycol(2,40)
LV_Modifycol(3,130)
LV_Modifycol(4,40)
LV_Modifycol(5,140)
LV_Modifycol(6,50)
LV_Modifycol(7,50)
LV_Modifycol(8,50)
LV_Modifycol(9,50)
LV_Modifycol(10,50)
Gui, Add, GroupBox, % "x10 y180 w190 h115", Axis states
Top := 200
Left := 12
rows := 4
cols := 2
label_width := 20
item_Width := 50
item_height := 25
col_width := 110
this.GuiAxisStates := []
Loop % rows {
row := A_Index - 1
axis := (row * cols) + 1
Loop % cols {
col := A_Index -1
Gui, Add, Text, % "x" Left + (col * col_width) " y" Top + (row * item_height) " w" label_width " center hwndhwnd", % this.AxisNames[axis]
Gui, Add, Text, % "x" Left + (col * col_width) + label_width " y" Top + (row * item_height) " w" item_width " center hwndhwnd"
this.GuiAxisStates[axis] := hwnd
axis++
}
}
Gui, Add, GroupBox, % "x10 y300 w190 h100", Hat states
Top := 320
rows := 2
cols := 2
this.GuiHatStates := []
Loop % rows {
row := A_Index - 1
hat := (row * cols) + 1
Loop % cols {
col := A_Index -1
Gui, Add, Text, % "x" Left + (col * col_width) " y" Top + (row * item_height) " w" label_width " center hwndhwnd", % hat ":"
Gui, Add, Text, % "x" Left + (col * col_width) + label_width " y" Top + (row * item_height) " w" item_width " center hwndhwnd"
this.GuiHatStates[hat] := hwnd
hat++
}
}
Gui, Add, GroupBox, % "x208 y180 w" this.GUI_WIDTH - 200 " h220", Button states
Top := 200
Left := 210
rows := 8
cols := 16
item_Width := 28
item_height := 25
this.GuiButtonStates := []
Loop % rows {
row := A_Index - 1
btn := (row * cols) + 1
Loop % cols {
col := A_Index - 1
Gui, Add, Text, % "x" Left + (col * item_width) " y" Top + (row * item_height) " w" item_width " center hwndhwnd", % Btn
this.GuiButtonStates[btn] := hwnd
btn++
}
}
Gui, Add, Text, xm Section, % "Time to process WM_INPUT message (Including time to assemble debug strings, but not update UI), in seconds: "
Gui, Add, Text, % "hwndhProcessTime w50 ys"
this.hProcessTime := hProcessTime
Gui, Show, y0, CHID Joystick Tester
fn := this.DeviceSelected.Bind(this)
GuiControl +g, % this.hLV, % fn
for handle, device in this.DevicesByHandle {
if (!device.NumButtons && !device.NumAxes){
; Ignore devices with no buttons or axes
continue
}
LV_Add(, handle, device.GUID, device.HumanName, device.NumButtons, device.AxisString, device.NumPOVs, device.VID, device.PID, device.UsagePage, device.Usage )
}
}
DeviceSelected(){
static LastSelected := -1
; Listviews fire g-labels on down event and up event of click, filter out up event
LV_GetText(handle, LV_GetNext())
if (A_GuiEvent = "i"){
fn := this.AxisChanged.Bind(this)
this.DevicesByHandle[handle].RegisterAxisCallback(fn)
fn := this.HatChanged.Bind(this)
this.DevicesByHandle[handle].RegisterHatCallback(fn)
fn := this.ButtonChanged.Bind(this)
this.DevicesByHandle[handle].RegisterButtonCallback(fn)
Loop 128 {
GuiControl, +cblack, % this.GuiButtonStates[A_Index]
GuiControl, , % this.GuiButtonStates[A_Index], % A_Index
}
Loop 8 {
GuiControl, , % this.GuiAxisStates[A_Index], % ""
}
Loop 4 {
GuiControl, , % this.GuiHatStates[A_Index], % ""
}
}
return 1
}
; The state of one or more buttons changed - walk the ButtonDelta array to see what changed.
ButtonChanged(device){
LV_GetText(handle, LV_GetNext())
if (device.handle = handle){
Loop % device.ButtonDelta.MaxIndex(){
; Update the GUI
if (device.ButtonDelta[A_Index].state){
col := "+cred"
} else {
col := "+cblack"
}
GuiControl, % col, % this.GuiButtonStates[device.ButtonDelta[A_Index].button]
GuiControl, , % this.GuiButtonStates[device.ButtonDelta[A_Index].button], % device.ButtonDelta[A_Index].button
}
; ToDo - remove from here as end of this routine is no longer end of WM_INPUT
GuiControl, , % this.hProcessTime, % device._ProcessTime
}
}
; The state of an Axis changed
AxisChanged(device){
LV_GetText(handle, LV_GetNext())
if (device.handle = handle){
Loop % device.AxisDelta.MaxIndex(){
; Update the GUI
GuiControl, , % this.GuiAxisStates[device.AxisDelta[A_Index].axis], % device.AxisDelta[A_Index].state
}
; ToDo - remove from here as end of this routine is no longer end of WM_INPUT
GuiControl, , % this.hProcessTime, % device._ProcessTime
}
}
; The state of a Hat changed
HatChanged(device){
LV_GetText(handle, LV_GetNext())
if (device.handle = handle){
Loop % device.HatDelta.MaxIndex(){
; Update the GUI
GuiControl, , % this.GuiHatStates[device.HatDelta[A_Index].hat], % device.HatDelta[A_Index].state
}
; ToDo - remove from here as end of this routine is no longer end of WM_INPUT
GuiControl, , % this.hProcessTime, % device._ProcessTime
}
}
}
Esc::
GuiClose:
ExitApp