-
Notifications
You must be signed in to change notification settings - Fork 71
/
Xinput.ahk
186 lines (163 loc) · 5.87 KB
/
Xinput.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
XinputSetState(index = 1, left_ = 0, right_ = 0)
{
static XINPUT_STATE
static XINPUT_SETSTATE
static XINPUT_VIBRATION
if not XINPUT_VIBRATION
VarSetCapacity(XINPUT_VIBRATION, 4)
if not XINPUT_SETSTATATE
{
XINPUT_HANDLE := dllcall("LoadLibrary", "wstr", "Xinput1_3.dll")
if not XINPUT_HANDLE
XINPUT_HANDLE := dllcall("GetModuleHandle", "wstr", "Xinput1_3.dll")
XINPUT_SETSTATE := dllcall("GetProcAddress", "Int", XINPUT_HANDLE, "astr", "XInputSetState")
}
index -= 1
numput(left_ * 65535, XINPUT_VIBRATION, "Short")
numput(right_ * 65535, XINPUT_VIBRATION, 2, "Short")
return dllcall(XINPUT_SETSTATE, int, index, ptr, &XINPUT_VIBRATION)
}
global XINPUT_GAMEPAD :=
(
"
WORD wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
"
)
global XINPUT_GAMEPAD_DPAD_UP
global XINPUT_GAMEPAD_DPAD_DOWN
global XINPUT_GAMEPAD_DPAD_LEFT
global XINPUT_GAMEPAD_DPAD_RIGHT
global XINPUT_GAMEPAD_START
global XINPUT_GAMEPAD_BACK
global XINPUT_GAMEPAD_LEFT_THUMB
global XINPUT_GAMEPAD_RIGHT_THUMB
global XINPUT_GAMEPAD_LEFT_SHOULDER
global XINPUT_GAMEPAD_RIGHT_SHOULDER
global XINPUT_GAMEPAD_A
global XINPUT_GAMEPAD_B
global XINPUT_GAMEPAD_X
global XINPUT_GAMEPAD_Y
global XINPUT_GAMEPAD_DPAD_UP_PREV
global XINPUT_GAMEPAD_DPAD_DOWN_PREV
global XINPUT_GAMEPAD_DPAD_LEFT_PREV
global XINPUT_GAMEPAD_DPAD_RIGHT_PREV
global XINPUT_GAMEPAD_START_PREV
global XINPUT_GAMEPAD_BACK_PREV
global XINPUT_GAMEPAD_LEFT_THUMB_PREV
global XINPUT_GAMEPAD_RIGHT_THUMB_PREV
global XINPUT_GAMEPAD_LEFT_SHOULDER_PREV
global XINPUT_GAMEPAD_RIGHT_SHOULDER_PREV
global XINPUT_GAMEPAD_A_PREV
global XINPUT_GAMEPAD_B_PREV
global XINPUT_GAMEPAD_X_PREV
global XINPUT_GAMEPAD_Y_PREV
global XINPUT_GAMEPAD_bLeftTrigger_prev
global XINPUT_GAMEPAD_bRightTrigger_prev
XINPUT_GAMEPAD := Struct("DWORD dwPacketNumber;`n" XINPUT_GAMEPAD)
XinputGetState(index = 1){
static XINPUT_STATE
static XINPUT_GETSTATE_ADRESS
index -= 1
if not XINPUT_GETSTATE_ADRESS
{
XINPUT_HANDLE := dllcall("LoadLibrary", "wstr", "Xinput1_3.dll")
if not XINPUT_HANDLE
XINPUT_HANDLE := dllcall("GetModuleHandle", "wstr", "Xinput1_3.dll")
if not XINPUT_HANDLE
return -1
XINPUT_GETSTATE_ADRESS := dllcall("GetProcAddress", "Int", XINPUT_HANDLE, "astr", "XInputGetState")
}
XINPUT_GAMEPAD_bLeftTrigger_prev := XINPUT_GAMEPAD.bLeftTrigger
XINPUT_GAMEPAD_bRightTrigger_prev := XINPUT_GAMEPAD.bRightTrigger
XINPUT_GAMEPAD_DPAD_UP_PREV := XINPUT_GAMEPAD_DPAD_UP
XINPUT_GAMEPAD_DPAD_DOWN_PREV := XINPUT_GAMEPAD_DPAD_DOWN
XINPUT_GAMEPAD_DPAD_LEFT_PREV := XINPUT_GAMEPAD_DPAD_LEFT
XINPUT_GAMEPAD_DPAD_RIGHT_PREV := XINPUT_GAMEPAD_DPAD_RIGHT
XINPUT_GAMEPAD_START_PREV := XINPUT_GAMEPAD_START
XINPUT_GAMEPAD_BACK_PREV := XINPUT_GAMEPAD_BACK
XINPUT_GAMEPAD_LEFT_THUMB_PREV := XINPUT_GAMEPAD_LEFT_THUMB
XINPUT_GAMEPAD_RIGHT_THUMB_PREV := XINPUT_GAMEPAD_RIGHT_THUMB
XINPUT_GAMEPAD_LEFT_SHOULDER_PREV := XINPUT_GAMEPAD_LEFT_SHOULDER
XINPUT_GAMEPAD_RIGHT_SHOULDER_PREV := XINPUT_GAMEPAD_RIGHT_SHOULDER
XINPUT_GAMEPAD_A_PREV := XINPUT_GAMEPAD_A
XINPUT_GAMEPAD_B_PREV := XINPUT_GAMEPAD_B
XINPUT_GAMEPAD_X_PREV := XINPUT_GAMEPAD_X
XINPUT_GAMEPAD_Y_PREV := XINPUT_GAMEPAD_Y
r := dllcall(XINPUT_GETSTATE_ADRESS, "int", index, "ptr", XINPUT_GAMEPAD[])
XINPUT_GAMEPAD_DPAD_UP := XINPUT_GAMEPAD.wButtons & 0x0001
XINPUT_GAMEPAD_DPAD_DOWN := XINPUT_GAMEPAD.wButtons & 0x0002
XINPUT_GAMEPAD_DPAD_LEFT := XINPUT_GAMEPAD.wButtons & 0x0004
XINPUT_GAMEPAD_DPAD_RIGHT := XINPUT_GAMEPAD.wButtons & 0x0008
XINPUT_GAMEPAD_START := XINPUT_GAMEPAD.wButtons & 0x0010
XINPUT_GAMEPAD_BACK := XINPUT_GAMEPAD.wButtons & 0x0020
XINPUT_GAMEPAD_LEFT_THUMB := XINPUT_GAMEPAD.wButtons & 0x0040
XINPUT_GAMEPAD_RIGHT_THUMB := XINPUT_GAMEPAD.wButtons & 0x0080
XINPUT_GAMEPAD_LEFT_SHOULDER := XINPUT_GAMEPAD.wButtons & 0x0100
XINPUT_GAMEPAD_RIGHT_SHOULDER := XINPUT_GAMEPAD.wButtons & 0x0200
XINPUT_GAMEPAD_A := XINPUT_GAMEPAD.wButtons & 0x1000
XINPUT_GAMEPAD_B := XINPUT_GAMEPAD.wButtons & 0x2000
XINPUT_GAMEPAD_X := XINPUT_GAMEPAD.wButtons & 0x4000
XINPUT_GAMEPAD_Y := XINPUT_GAMEPAD.wButtons & 0x8000
return r
}
XinputGetLeftStickAngle()
{
x := XINPUT_GAMEPAD.sThumbLX/32767
y := XINPUT_GAMEPAD.sThumbLY/32767
if ( (x > 0) and (y > 0) )
return ATan(x/y) * 57.29578
else if ( (x > 0) and (y < 0) )
return 180 - (ATan(x/abs(y)) * 57.29578)
else if ( (x < 0) and (y < 0) )
return 180 + (ATan(abs(x)/abs(y)) * 57.29578)
else if ( (x < 0) and (y > 0) )
return 360 - (ATan(abs(x)/y) * 57.29578)
}
XinputGetEvent(index)
{
if XinputGetState(1)
return r
ret := []
events := [
, [XINPUT_GAMEPAD_DPAD_UP_PREV, XINPUT_GAMEPAD_DPAD_UP]
, [XINPUT_GAMEPAD_DPAD_DOWN_PREV, XINPUT_GAMEPAD_DPAD_DOWN]
, [XINPUT_GAMEPAD_DPAD_LEFT_PREV, XINPUT_GAMEPAD_DPAD_LEFT]
, [XINPUT_GAMEPAD_DPAD_RIGHT_PREV, XINPUT_GAMEPAD_DPAD_RIGHT]
, [XINPUT_GAMEPAD_A_PREV, XINPUT_GAMEPAD_A]
, [XINPUT_GAMEPAD_B_PREV, XINPUT_GAMEPAD_B]
, [XINPUT_GAMEPAD_X_PREV, XINPUT_GAMEPAD_X]
, [XINPUT_GAMEPAD_Y_PREV, XINPUT_GAMEPAD_Y]
, [XINPUT_GAMEPAD_LEFT_SHOULDER_PREV, XINPUT_GAMEPAD_LEFT_SHOULDER]
, [XINPUT_GAMEPAD_RIGHT_SHOULDER_PREV, XINPUT_GAMEPAD_RIGHT_SHOULDER]
, [XINPUT_GAMEPAD_bLeftTrigger_prev, XINPUT_GAMEPAD.bLeftTrigger]
, [XINPUT_GAMEPAD_bRightTrigger_prev, XINPUT_GAMEPAD.bRightTrigger]
, [XINPUT_GAMEPAD_BACK_PREV, XINPUT_GAMEPAD_BACK]
, [XINPUT_GAMEPAD_START_PREV, XINPUT_GAMEPAD_START]
, [XINPUT_GAMEPAD_LEFT_THUMB_PREV, XINPUT_GAMEPAD_LEFT_THUMB]
, [XINPUT_GAMEPAD_RIGHT_THUMB_PREV, XINPUT_GAMEPAD_RIGHT_THUMB]]
for k, v in events
v[1] and not v[2] ? ret.insert(-1) : v[2] and not v[1] ? ret.insert(1) : ret.insert(0)
return ret
}
/*
#include <_Struct>
struct(def) {
return new _Struct(def)
}
Loop
{
XinputGetState()
text := XinputGetLeftStickAngle()
if getkeystate("a")
tooltip, %text%
if getkeystate("esc")
ExitApp
}
;exitapp
*/