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