1 module directx.xinput;
2 /***************************************************************************
3  *                                                                          *
4  *   XInput.h -- This module defines XBOX controller APIs                   *
5  *               and constansts for the Windows platform.                   *
6  *                                                                          *
7  *   Copyright (c) Microsoft Corp. All rights reserved.                     *
8  *                                                                          *
9  ***************************************************************************/
10 
11 import directx.win32;
12 
13 // note: 9.1.0 is reduced multi-platform(winxp-win8, +xbox?) subset of XInput
14 //      that only provides most basic stuff. For advanced functionality 
15 //      use 1.3 or 1.4.
16 //      9.1.0 has its own enum values.
17 version = XINPUT_USE_1_3;
18 
19 // Current name of the DLL shipped in the same SDK as this header.
20 // The name reflects the current version
21 version(XINPUT_USE_9_1_0)
22 {
23 	enum XINPUT_DLL_A = "xinput9_1_0.dll";
24 	enum XINPUT_DLL_W = "xinput9_1_0.dll"w;
25 }
26 else
27 {
28 	enum XINPUT_DLL_A = "xinput1_3.dll";
29 	enum XINPUT_DLL_W = "xinput1_3.dll"w;
30 }
31 
32 alias XINPUT_DLL_W XINPUT_DLL;
33 
34 //
35 // Device types available in XINPUT_CAPABILITIES
36 //
37 enum XINPUT_DEVTYPE_GAMEPAD         = 0x01;
38 
39 //
40 // Device subtypes available in XINPUT_CAPABILITIES
41 //
42 enum XINPUT_DEVSUBTYPE_GAMEPAD        = 0x01;
43 
44 
45 version(XINPUT_USE_9_1_0) 
46 {
47 }
48 else
49 {
50 	enum XINPUT_DEVSUBTYPE_WHEEL          = 0x02;
51 	enum XINPUT_DEVSUBTYPE_ARCADE_STICK   = 0x03;
52 	enum XINPUT_DEVSUBTYPE_FLIGHT_SICK    = 0x04;
53 	enum XINPUT_DEVSUBTYPE_DANCE_PAD      = 0x05;
54 	enum XINPUT_DEVSUBTYPE_GUITAR         = 0x06;
55 	enum XINPUT_DEVSUBTYPE_DRUM_KIT       = 0x08;
56 }
57 
58 
59 
60 //
61 // Flags for XINPUT_CAPABILITIES
62 //
63 enum XINPUT_CAPS_VOICE_SUPPORTED      = 0x0004;
64 
65 //
66 // Constants for gamepad buttons
67 //
68 enum XINPUT_GAMEPAD_DPAD_UP           = 0x0001;
69 enum XINPUT_GAMEPAD_DPAD_DOWN         = 0x0002;
70 enum XINPUT_GAMEPAD_DPAD_LEFT         = 0x0004;
71 enum XINPUT_GAMEPAD_DPAD_RIGHT        = 0x0008;
72 enum XINPUT_GAMEPAD_START             = 0x0010;
73 enum XINPUT_GAMEPAD_BACK              = 0x0020;
74 enum XINPUT_GAMEPAD_LEFT_THUMB        = 0x0040;
75 enum XINPUT_GAMEPAD_RIGHT_THUMB       = 0x0080;
76 enum XINPUT_GAMEPAD_LEFT_SHOULDER     = 0x0100;
77 enum XINPUT_GAMEPAD_RIGHT_SHOULDER    = 0x0200;
78 enum XINPUT_GAMEPAD_A                 = 0x1000;
79 enum XINPUT_GAMEPAD_B                 = 0x2000;
80 enum XINPUT_GAMEPAD_X                 = 0x4000;
81 enum XINPUT_GAMEPAD_Y                 = 0x8000;
82 
83 
84 //
85 // Gamepad thresholds
86 //
87 enum XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE   = 7849;
88 enum XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE  = 8689;
89 enum XINPUT_GAMEPAD_TRIGGER_THRESHOLD     = 30;
90 
91 //
92 // Flags to pass to XInputGetCapabilities
93 //
94 enum XINPUT_FLAG_GAMEPAD              = 0x00000001;
95 
96 
97 version(XINPUT_USE_9_1_0)
98 {
99 }
100 else
101 {
102 //
103 // Devices that support batteries
104 //
105 enum BATTERY_DEVTYPE_GAMEPAD          = 0x00;
106 enum BATTERY_DEVTYPE_HEADSET          = 0x01;
107 
108 //
109 // Flags for battery status level
110 //
111 enum BATTERY_TYPE_DISCONNECTED        = 0x00;    // This device is not connected
112 enum BATTERY_TYPE_WIRED               = 0x01;    // Wired device, no battery
113 enum BATTERY_TYPE_ALKALINE            = 0x02;    // Alkaline battery source
114 enum BATTERY_TYPE_NIMH                = 0x03;    // Nickel Metal Hydride battery source
115 enum BATTERY_TYPE_UNKNOWN             = 0xFF;    // Cannot determine the battery type
116 
117 // These are only valid for wireless, connected devices, with known battery types
118 // The amount of use time remaining depends on the type of device.
119 enum BATTERY_LEVEL_EMPTY              = 0x00;
120 enum BATTERY_LEVEL_LOW                = 0x01;
121 enum BATTERY_LEVEL_MEDIUM             = 0x02;
122 enum BATTERY_LEVEL_FULL               = 0x03;
123 
124 // User index definitions
125 enum XUSER_MAX_COUNT                  = 4;
126 
127 enum XUSER_INDEX_ANY                  = 0x000000FF;
128 
129 
130 //
131 // Codes returned for the gamepad keystroke
132 //
133 
134 enum VK_PAD_A                         = 0x5800;
135 enum VK_PAD_B                         = 0x5801;
136 enum VK_PAD_X                         = 0x5802;
137 enum VK_PAD_Y                         = 0x5803;
138 enum VK_PAD_RSHOULDER                 = 0x5804;
139 enum VK_PAD_LSHOULDER                 = 0x5805;
140 enum VK_PAD_LTRIGGER                  = 0x5806;
141 enum VK_PAD_RTRIGGER                  = 0x5807;
142 
143 enum VK_PAD_DPAD_UP                   = 0x5810;
144 enum VK_PAD_DPAD_DOWN                 = 0x5811;
145 enum VK_PAD_DPAD_LEFT                 = 0x5812;
146 enum VK_PAD_DPAD_RIGHT                = 0x5813;
147 enum VK_PAD_START                     = 0x5814;
148 enum VK_PAD_BACK                      = 0x5815;
149 enum VK_PAD_LTHUMB_PRESS              = 0x5816;
150 enum VK_PAD_RTHUMB_PRESS              = 0x5817;
151 
152 enum VK_PAD_LTHUMB_UP                 = 0x5820;
153 enum VK_PAD_LTHUMB_DOWN               = 0x5821;
154 enum VK_PAD_LTHUMB_RIGHT              = 0x5822;
155 enum VK_PAD_LTHUMB_LEFT               = 0x5823;
156 enum VK_PAD_LTHUMB_UPLEFT             = 0x5824;
157 enum VK_PAD_LTHUMB_UPRIGHT            = 0x5825;
158 enum VK_PAD_LTHUMB_DOWNRIGHT          = 0x5826;
159 enum VK_PAD_LTHUMB_DOWNLEFT           = 0x5827;
160 
161 enum VK_PAD_RTHUMB_UP                 = 0x5830;
162 enum VK_PAD_RTHUMB_DOWN               = 0x5831;
163 enum VK_PAD_RTHUMB_RIGHT              = 0x5832;
164 enum VK_PAD_RTHUMB_LEFT               = 0x5833;
165 enum VK_PAD_RTHUMB_UPLEFT             = 0x5834;
166 enum VK_PAD_RTHUMB_UPRIGHT            = 0x5835;
167 enum VK_PAD_RTHUMB_DOWNRIGHT          = 0x5836;
168 enum VK_PAD_RTHUMB_DOWNLEFT           = 0x5837;
169 
170 //
171 // Flags used in XINPUT_KEYSTROKE
172 //
173 enum XINPUT_KEYSTROKE_KEYDOWN         = 0x0001;
174 enum XINPUT_KEYSTROKE_KEYUP           = 0x0002;
175 enum XINPUT_KEYSTROKE_REPEAT          = 0x0004;
176 
177 }
178 
179 //
180 // Structures used by XInput APIs
181 //
182 struct _XINPUT_GAMEPAD
183 {
184     WORD                                wButtons;
185     BYTE                                bLeftTrigger;
186     BYTE                                bRightTrigger;
187     SHORT                               sThumbLX;
188     SHORT                               sThumbLY;
189     SHORT                               sThumbRX;
190     SHORT                               sThumbRY;
191 } 
192 alias _XINPUT_GAMEPAD XINPUT_GAMEPAD;
193 alias _XINPUT_GAMEPAD* PXINPUT_GAMEPAD;
194 
195 struct _XINPUT_STATE
196 {
197     DWORD                               dwPacketNumber;
198     XINPUT_GAMEPAD                      Gamepad;
199 } 
200 alias _XINPUT_STATE XINPUT_STATE;
201 alias _XINPUT_STATE* PXINPUT_STATE;
202 
203 struct _XINPUT_VIBRATION
204 {
205     WORD                                wLeftMotorSpeed;
206     WORD                                wRightMotorSpeed;
207 }
208 alias _XINPUT_VIBRATION XINPUT_VIBRATION;
209 alias _XINPUT_VIBRATION* PXINPUT_VIBRATION;
210 
211 struct _XINPUT_CAPABILITIES
212 {
213     BYTE                                Type;
214     BYTE                                SubType;
215     WORD                                Flags;
216     XINPUT_GAMEPAD                      Gamepad;
217     XINPUT_VIBRATION                    Vibration;
218 } 
219 alias _XINPUT_CAPABILITIES XINPUT_CAPABILITIES;
220 alias _XINPUT_CAPABILITIES* PXINPUT_CAPABILITIES;
221 
222 version(XINPUT_USE_9_1_0)
223 {
224 }
225 else
226 {
227 struct _XINPUT_BATTERY_INFORMATION
228 {
229     BYTE BatteryType;
230     BYTE BatteryLevel;
231 }
232 alias _XINPUT_BATTERY_INFORMATION XINPUT_BATTERY_INFORMATION;
233 alias _XINPUT_BATTERY_INFORMATION* PXINPUT_BATTERY_INFORMATION;
234 
235 struct _XINPUT_KEYSTROKE
236 {
237     WORD    VirtualKey;
238     WCHAR   Unicode;
239     WORD    Flags;
240     BYTE    UserIndex;
241     BYTE    HidCode;
242 }
243 alias _XINPUT_KEYSTROKE XINPUT_KEYSTROKE;
244 alias _XINPUT_KEYSTROKE* PXINPUT_KEYSTROKE;
245 
246 }
247 
248 //
249 // XInput APIs
250 //
251 extern (Windows) 
252 {
253 
254 DWORD XInputGetState
255 (
256     in  DWORD         dwUserIndex,  // Index of the gamer associated with the device
257     /*out*/ XINPUT_STATE* pState        // Receives the current state
258 );
259 
260 DWORD XInputSetState
261 (
262     in DWORD             dwUserIndex,  // Index of the gamer associated with the device
263     in XINPUT_VIBRATION* pVibration    // The vibration information to send to the controller
264 );
265 
266 DWORD XInputGetCapabilities
267 (
268     in  DWORD                dwUserIndex,   // Index of the gamer associated with the device
269     in  DWORD                dwFlags,       // Input flags that identify the device type
270     /*out*/ XINPUT_CAPABILITIES* pCapabilities  // Receives the capabilities
271 );
272 
273 void XInputEnable
274 (
275     in BOOL enable     // [in] Indicates whether xinput is enabled or disabled. 
276 );
277 
278 DWORD XInputGetDSoundAudioDeviceGuids
279 (
280     in  DWORD dwUserIndex,          // Index of the gamer associated with the device
281     /*out*/ GUID* pDSoundRenderGuid,    // DSound device ID for render
282     /*out*/ GUID* pDSoundCaptureGuid    // DSound device ID for capture
283 );
284 
285 version(XINPUT_USE_9_1_0)
286 {
287 }
288 else
289 {
290 
291 DWORD XInputGetBatteryInformation
292 (
293     in  DWORD                       dwUserIndex,        // Index of the gamer associated with the device
294     in  BYTE                        devType,            // Which device on this user index
295     /*out*/ XINPUT_BATTERY_INFORMATION* pBatteryInformation // Contains the level and types of batteries
296 );
297 
298 DWORD XInputGetKeystroke
299 (
300     in       DWORD dwUserIndex,              // Index of the gamer associated with the device
301              DWORD dwReserved,               // Reserved for future use
302     /*out*/  PXINPUT_KEYSTROKE pKeystroke    // Pointer to an XINPUT_KEYSTROKE structure that receives an input event.
303 );
304 
305 }
306 
307 }
308