Xinput.h 11 KB

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