XInput.h 8.8 KB

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