isteaminput.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. // This file is provided under The MIT License as part of Steamworks.NET.
  2. // Copyright (c) 2013-2019 Riley Labrecque
  3. // Please see the included LICENSE.txt for additional information.
  4. // This file is automatically generated.
  5. // Changes to this file will be reverted when you update Steamworks.NET
  6. #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH
  7. #define DISABLESTEAMWORKS
  8. #endif
  9. #if !DISABLESTEAMWORKS
  10. using System.Runtime.InteropServices;
  11. using IntPtr = System.IntPtr;
  12. namespace Steamworks {
  13. public static class SteamInput {
  14. /// <summary>
  15. /// <para> Init and Shutdown must be called when starting/ending use of this interface</para>
  16. /// </summary>
  17. public static bool Init() {
  18. InteropHelp.TestIfAvailableClient();
  19. return NativeMethods.ISteamInput_Init(CSteamAPIContext.GetSteamInput());
  20. }
  21. public static bool Shutdown() {
  22. InteropHelp.TestIfAvailableClient();
  23. return NativeMethods.ISteamInput_Shutdown(CSteamAPIContext.GetSteamInput());
  24. }
  25. /// <summary>
  26. /// <para> Synchronize API state with the latest Steam Controller inputs available. This</para>
  27. /// <para> is performed automatically by SteamAPI_RunCallbacks, but for the absolute lowest</para>
  28. /// <para> possible latency, you call this directly before reading controller state. This must</para>
  29. /// <para> be called from somewhere before GetConnectedControllers will return any handles</para>
  30. /// </summary>
  31. public static void RunFrame() {
  32. InteropHelp.TestIfAvailableClient();
  33. NativeMethods.ISteamInput_RunFrame(CSteamAPIContext.GetSteamInput());
  34. }
  35. /// <summary>
  36. /// <para> Enumerate currently connected Steam Input enabled devices - developers can opt in controller by type (ex: Xbox/Playstation/etc) via</para>
  37. /// <para> the Steam Input settings in the Steamworks site or users can opt-in in their controller settings in Steam.</para>
  38. /// <para> handlesOut should point to a STEAM_INPUT_MAX_COUNT sized array of InputHandle_t handles</para>
  39. /// <para> Returns the number of handles written to handlesOut</para>
  40. /// </summary>
  41. public static int GetConnectedControllers(InputHandle_t[] handlesOut) {
  42. InteropHelp.TestIfAvailableClient();
  43. if (handlesOut != null && handlesOut.Length != Constants.STEAM_INPUT_MAX_COUNT) {
  44. throw new System.ArgumentException("handlesOut must be the same size as Constants.STEAM_INPUT_MAX_COUNT!");
  45. }
  46. return NativeMethods.ISteamInput_GetConnectedControllers(CSteamAPIContext.GetSteamInput(), handlesOut);
  47. }
  48. /// <summary>
  49. /// <para>-----------------------------------------------------------------------------</para>
  50. /// <para> ACTION SETS</para>
  51. /// <para>-----------------------------------------------------------------------------</para>
  52. /// <para> Lookup the handle for an Action Set. Best to do this once on startup, and store the handles for all future API calls.</para>
  53. /// </summary>
  54. public static InputActionSetHandle_t GetActionSetHandle(string pszActionSetName) {
  55. InteropHelp.TestIfAvailableClient();
  56. using (var pszActionSetName2 = new InteropHelp.UTF8StringHandle(pszActionSetName)) {
  57. return (InputActionSetHandle_t)NativeMethods.ISteamInput_GetActionSetHandle(CSteamAPIContext.GetSteamInput(), pszActionSetName2);
  58. }
  59. }
  60. /// <summary>
  61. /// <para> Reconfigure the controller to use the specified action set (ie 'Menu', 'Walk' or 'Drive')</para>
  62. /// <para> This is cheap, and can be safely called repeatedly. It's often easier to repeatedly call it in</para>
  63. /// <para> your state loops, instead of trying to place it in all of your state transitions.</para>
  64. /// </summary>
  65. public static void ActivateActionSet(InputHandle_t inputHandle, InputActionSetHandle_t actionSetHandle) {
  66. InteropHelp.TestIfAvailableClient();
  67. NativeMethods.ISteamInput_ActivateActionSet(CSteamAPIContext.GetSteamInput(), inputHandle, actionSetHandle);
  68. }
  69. public static InputActionSetHandle_t GetCurrentActionSet(InputHandle_t inputHandle) {
  70. InteropHelp.TestIfAvailableClient();
  71. return (InputActionSetHandle_t)NativeMethods.ISteamInput_GetCurrentActionSet(CSteamAPIContext.GetSteamInput(), inputHandle);
  72. }
  73. /// <summary>
  74. /// <para> ACTION SET LAYERS</para>
  75. /// </summary>
  76. public static void ActivateActionSetLayer(InputHandle_t inputHandle, InputActionSetHandle_t actionSetLayerHandle) {
  77. InteropHelp.TestIfAvailableClient();
  78. NativeMethods.ISteamInput_ActivateActionSetLayer(CSteamAPIContext.GetSteamInput(), inputHandle, actionSetLayerHandle);
  79. }
  80. public static void DeactivateActionSetLayer(InputHandle_t inputHandle, InputActionSetHandle_t actionSetLayerHandle) {
  81. InteropHelp.TestIfAvailableClient();
  82. NativeMethods.ISteamInput_DeactivateActionSetLayer(CSteamAPIContext.GetSteamInput(), inputHandle, actionSetLayerHandle);
  83. }
  84. public static void DeactivateAllActionSetLayers(InputHandle_t inputHandle) {
  85. InteropHelp.TestIfAvailableClient();
  86. NativeMethods.ISteamInput_DeactivateAllActionSetLayers(CSteamAPIContext.GetSteamInput(), inputHandle);
  87. }
  88. /// <summary>
  89. /// <para> Enumerate currently active layers.</para>
  90. /// <para> handlesOut should point to a STEAM_INPUT_MAX_ACTIVE_LAYERS sized array of ControllerActionSetHandle_t handles</para>
  91. /// <para> Returns the number of handles written to handlesOut</para>
  92. /// </summary>
  93. public static int GetActiveActionSetLayers(InputHandle_t inputHandle, InputActionSetHandle_t[] handlesOut) {
  94. InteropHelp.TestIfAvailableClient();
  95. if (handlesOut != null && handlesOut.Length != Constants.STEAM_INPUT_MAX_ACTIVE_LAYERS) {
  96. throw new System.ArgumentException("handlesOut must be the same size as Constants.STEAM_INPUT_MAX_ACTIVE_LAYERS!");
  97. }
  98. return NativeMethods.ISteamInput_GetActiveActionSetLayers(CSteamAPIContext.GetSteamInput(), inputHandle, handlesOut);
  99. }
  100. /// <summary>
  101. /// <para>-----------------------------------------------------------------------------</para>
  102. /// <para> ACTIONS</para>
  103. /// <para>-----------------------------------------------------------------------------</para>
  104. /// <para> Lookup the handle for a digital action. Best to do this once on startup, and store the handles for all future API calls.</para>
  105. /// </summary>
  106. public static InputDigitalActionHandle_t GetDigitalActionHandle(string pszActionName) {
  107. InteropHelp.TestIfAvailableClient();
  108. using (var pszActionName2 = new InteropHelp.UTF8StringHandle(pszActionName)) {
  109. return (InputDigitalActionHandle_t)NativeMethods.ISteamInput_GetDigitalActionHandle(CSteamAPIContext.GetSteamInput(), pszActionName2);
  110. }
  111. }
  112. /// <summary>
  113. /// <para> Returns the current state of the supplied digital game action</para>
  114. /// </summary>
  115. public static InputDigitalActionData_t GetDigitalActionData(InputHandle_t inputHandle, InputDigitalActionHandle_t digitalActionHandle) {
  116. InteropHelp.TestIfAvailableClient();
  117. return NativeMethods.ISteamInput_GetDigitalActionData(CSteamAPIContext.GetSteamInput(), inputHandle, digitalActionHandle);
  118. }
  119. /// <summary>
  120. /// <para> Get the origin(s) for a digital action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.</para>
  121. /// <para> originsOut should point to a STEAM_INPUT_MAX_ORIGINS sized array of EInputActionOrigin handles. The EInputActionOrigin enum will get extended as support for new controller controllers gets added to</para>
  122. /// <para> the Steam client and will exceed the values from this header, please check bounds if you are using a look up table.</para>
  123. /// </summary>
  124. public static int GetDigitalActionOrigins(InputHandle_t inputHandle, InputActionSetHandle_t actionSetHandle, InputDigitalActionHandle_t digitalActionHandle, EInputActionOrigin[] originsOut) {
  125. InteropHelp.TestIfAvailableClient();
  126. if (originsOut != null && originsOut.Length != Constants.STEAM_INPUT_MAX_ORIGINS) {
  127. throw new System.ArgumentException("originsOut must be the same size as Constants.STEAM_INPUT_MAX_ORIGINS!");
  128. }
  129. return NativeMethods.ISteamInput_GetDigitalActionOrigins(CSteamAPIContext.GetSteamInput(), inputHandle, actionSetHandle, digitalActionHandle, originsOut);
  130. }
  131. /// <summary>
  132. /// <para> Lookup the handle for an analog action. Best to do this once on startup, and store the handles for all future API calls.</para>
  133. /// </summary>
  134. public static InputAnalogActionHandle_t GetAnalogActionHandle(string pszActionName) {
  135. InteropHelp.TestIfAvailableClient();
  136. using (var pszActionName2 = new InteropHelp.UTF8StringHandle(pszActionName)) {
  137. return (InputAnalogActionHandle_t)NativeMethods.ISteamInput_GetAnalogActionHandle(CSteamAPIContext.GetSteamInput(), pszActionName2);
  138. }
  139. }
  140. /// <summary>
  141. /// <para> Returns the current state of these supplied analog game action</para>
  142. /// </summary>
  143. public static InputAnalogActionData_t GetAnalogActionData(InputHandle_t inputHandle, InputAnalogActionHandle_t analogActionHandle) {
  144. InteropHelp.TestIfAvailableClient();
  145. return NativeMethods.ISteamInput_GetAnalogActionData(CSteamAPIContext.GetSteamInput(), inputHandle, analogActionHandle);
  146. }
  147. /// <summary>
  148. /// <para> Get the origin(s) for an analog action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.</para>
  149. /// <para> originsOut should point to a STEAM_INPUT_MAX_ORIGINS sized array of EInputActionOrigin handles. The EInputActionOrigin enum will get extended as support for new controller controllers gets added to</para>
  150. /// <para> the Steam client and will exceed the values from this header, please check bounds if you are using a look up table.</para>
  151. /// </summary>
  152. public static int GetAnalogActionOrigins(InputHandle_t inputHandle, InputActionSetHandle_t actionSetHandle, InputAnalogActionHandle_t analogActionHandle, EInputActionOrigin[] originsOut) {
  153. InteropHelp.TestIfAvailableClient();
  154. if (originsOut != null && originsOut.Length != Constants.STEAM_INPUT_MAX_ORIGINS) {
  155. throw new System.ArgumentException("originsOut must be the same size as Constants.STEAM_INPUT_MAX_ORIGINS!");
  156. }
  157. return NativeMethods.ISteamInput_GetAnalogActionOrigins(CSteamAPIContext.GetSteamInput(), inputHandle, actionSetHandle, analogActionHandle, originsOut);
  158. }
  159. /// <summary>
  160. /// <para> Get a local path to art for on-screen glyph for a particular origin</para>
  161. /// </summary>
  162. public static string GetGlyphForActionOrigin(EInputActionOrigin eOrigin) {
  163. InteropHelp.TestIfAvailableClient();
  164. return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamInput_GetGlyphForActionOrigin(CSteamAPIContext.GetSteamInput(), eOrigin));
  165. }
  166. /// <summary>
  167. /// <para> Returns a localized string (from Steam's language setting) for the specified origin.</para>
  168. /// </summary>
  169. public static string GetStringForActionOrigin(EInputActionOrigin eOrigin) {
  170. InteropHelp.TestIfAvailableClient();
  171. return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamInput_GetStringForActionOrigin(CSteamAPIContext.GetSteamInput(), eOrigin));
  172. }
  173. /// <summary>
  174. /// <para> Stop analog momentum for the action if it is a mouse action in trackball mode</para>
  175. /// </summary>
  176. public static void StopAnalogActionMomentum(InputHandle_t inputHandle, InputAnalogActionHandle_t eAction) {
  177. InteropHelp.TestIfAvailableClient();
  178. NativeMethods.ISteamInput_StopAnalogActionMomentum(CSteamAPIContext.GetSteamInput(), inputHandle, eAction);
  179. }
  180. /// <summary>
  181. /// <para> Returns raw motion data from the specified device</para>
  182. /// </summary>
  183. public static InputMotionData_t GetMotionData(InputHandle_t inputHandle) {
  184. InteropHelp.TestIfAvailableClient();
  185. return NativeMethods.ISteamInput_GetMotionData(CSteamAPIContext.GetSteamInput(), inputHandle);
  186. }
  187. /// <summary>
  188. /// <para>-----------------------------------------------------------------------------</para>
  189. /// <para> OUTPUTS</para>
  190. /// <para>-----------------------------------------------------------------------------</para>
  191. /// <para> Trigger a vibration event on supported controllers - Steam will translate these commands into haptic pulses for Steam Controllers</para>
  192. /// </summary>
  193. public static void TriggerVibration(InputHandle_t inputHandle, ushort usLeftSpeed, ushort usRightSpeed) {
  194. InteropHelp.TestIfAvailableClient();
  195. NativeMethods.ISteamInput_TriggerVibration(CSteamAPIContext.GetSteamInput(), inputHandle, usLeftSpeed, usRightSpeed);
  196. }
  197. /// <summary>
  198. /// <para> Set the controller LED color on supported controllers. nFlags is a bitmask of values from ESteamInputLEDFlag - 0 will default to setting a color. Steam will handle</para>
  199. /// <para> the behavior on exit of your program so you don't need to try restore the default as you are shutting down</para>
  200. /// </summary>
  201. public static void SetLEDColor(InputHandle_t inputHandle, byte nColorR, byte nColorG, byte nColorB, uint nFlags) {
  202. InteropHelp.TestIfAvailableClient();
  203. NativeMethods.ISteamInput_SetLEDColor(CSteamAPIContext.GetSteamInput(), inputHandle, nColorR, nColorG, nColorB, nFlags);
  204. }
  205. /// <summary>
  206. /// <para> Trigger a haptic pulse on a Steam Controller - if you are approximating rumble you may want to use TriggerVibration instead.</para>
  207. /// <para> Good uses for Haptic pulses include chimes, noises, or directional gameplay feedback (taking damage, footstep locations, etc).</para>
  208. /// </summary>
  209. public static void TriggerHapticPulse(InputHandle_t inputHandle, ESteamControllerPad eTargetPad, ushort usDurationMicroSec) {
  210. InteropHelp.TestIfAvailableClient();
  211. NativeMethods.ISteamInput_TriggerHapticPulse(CSteamAPIContext.GetSteamInput(), inputHandle, eTargetPad, usDurationMicroSec);
  212. }
  213. /// <summary>
  214. /// <para> Trigger a haptic pulse with a duty cycle of usDurationMicroSec / usOffMicroSec, unRepeat times. If you are approximating rumble you may want to use TriggerVibration instead.</para>
  215. /// <para> nFlags is currently unused and reserved for future use.</para>
  216. /// </summary>
  217. public static void TriggerRepeatedHapticPulse(InputHandle_t inputHandle, ESteamControllerPad eTargetPad, ushort usDurationMicroSec, ushort usOffMicroSec, ushort unRepeat, uint nFlags) {
  218. InteropHelp.TestIfAvailableClient();
  219. NativeMethods.ISteamInput_TriggerRepeatedHapticPulse(CSteamAPIContext.GetSteamInput(), inputHandle, eTargetPad, usDurationMicroSec, usOffMicroSec, unRepeat, nFlags);
  220. }
  221. /// <summary>
  222. /// <para>-----------------------------------------------------------------------------</para>
  223. /// <para> Utility functions availible without using the rest of Steam Input API</para>
  224. /// <para>-----------------------------------------------------------------------------</para>
  225. /// <para> Invokes the Steam overlay and brings up the binding screen if the user is using Big Picture Mode</para>
  226. /// <para> If the user is not in Big Picture Mode it will open up the binding in a new window</para>
  227. /// </summary>
  228. public static bool ShowBindingPanel(InputHandle_t inputHandle) {
  229. InteropHelp.TestIfAvailableClient();
  230. return NativeMethods.ISteamInput_ShowBindingPanel(CSteamAPIContext.GetSteamInput(), inputHandle);
  231. }
  232. /// <summary>
  233. /// <para> Returns the input type for a particular handle</para>
  234. /// </summary>
  235. public static ESteamInputType GetInputTypeForHandle(InputHandle_t inputHandle) {
  236. InteropHelp.TestIfAvailableClient();
  237. return NativeMethods.ISteamInput_GetInputTypeForHandle(CSteamAPIContext.GetSteamInput(), inputHandle);
  238. }
  239. /// <summary>
  240. /// <para> Returns the associated controller handle for the specified emulated gamepad - can be used with the above 2 functions</para>
  241. /// <para> to identify controllers presented to your game over Xinput. Returns 0 if the Xinput index isn't associated with Steam Input</para>
  242. /// </summary>
  243. public static InputHandle_t GetControllerForGamepadIndex(int nIndex) {
  244. InteropHelp.TestIfAvailableClient();
  245. return (InputHandle_t)NativeMethods.ISteamInput_GetControllerForGamepadIndex(CSteamAPIContext.GetSteamInput(), nIndex);
  246. }
  247. /// <summary>
  248. /// <para> Returns the associated gamepad index for the specified controller, if emulating a gamepad or -1 if not associated with an Xinput index</para>
  249. /// </summary>
  250. public static int GetGamepadIndexForController(InputHandle_t ulinputHandle) {
  251. InteropHelp.TestIfAvailableClient();
  252. return NativeMethods.ISteamInput_GetGamepadIndexForController(CSteamAPIContext.GetSteamInput(), ulinputHandle);
  253. }
  254. /// <summary>
  255. /// <para> Returns a localized string (from Steam's language setting) for the specified Xbox controller origin.</para>
  256. /// </summary>
  257. public static string GetStringForXboxOrigin(EXboxOrigin eOrigin) {
  258. InteropHelp.TestIfAvailableClient();
  259. return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamInput_GetStringForXboxOrigin(CSteamAPIContext.GetSteamInput(), eOrigin));
  260. }
  261. /// <summary>
  262. /// <para> Get a local path to art for on-screen glyph for a particular Xbox controller origin</para>
  263. /// </summary>
  264. public static string GetGlyphForXboxOrigin(EXboxOrigin eOrigin) {
  265. InteropHelp.TestIfAvailableClient();
  266. return InteropHelp.PtrToStringUTF8(NativeMethods.ISteamInput_GetGlyphForXboxOrigin(CSteamAPIContext.GetSteamInput(), eOrigin));
  267. }
  268. /// <summary>
  269. /// <para> Get the equivalent ActionOrigin for a given Xbox controller origin this can be chained with GetGlyphForActionOrigin to provide future proof glyphs for</para>
  270. /// <para> non-Steam Input API action games. Note - this only translates the buttons directly and doesn't take into account any remapping a user has made in their configuration</para>
  271. /// </summary>
  272. public static EInputActionOrigin GetActionOriginFromXboxOrigin(InputHandle_t inputHandle, EXboxOrigin eOrigin) {
  273. InteropHelp.TestIfAvailableClient();
  274. return NativeMethods.ISteamInput_GetActionOriginFromXboxOrigin(CSteamAPIContext.GetSteamInput(), inputHandle, eOrigin);
  275. }
  276. /// <summary>
  277. /// <para> Convert an origin to another controller type - for inputs not present on the other controller type this will return k_EInputActionOrigin_None</para>
  278. /// <para> When a new input type is added you will be able to pass in k_ESteamInputType_Unknown and the closest origin that your version of the SDK recognized will be returned</para>
  279. /// <para> ex: if a Playstation 5 controller was released this function would return Playstation 4 origins.</para>
  280. /// </summary>
  281. public static EInputActionOrigin TranslateActionOrigin(ESteamInputType eDestinationInputType, EInputActionOrigin eSourceOrigin) {
  282. InteropHelp.TestIfAvailableClient();
  283. return NativeMethods.ISteamInput_TranslateActionOrigin(CSteamAPIContext.GetSteamInput(), eDestinationInputType, eSourceOrigin);
  284. }
  285. /// <summary>
  286. /// <para> Get the binding revision for a given device. Returns false if the handle was not valid or if a mapping is not yet loaded for the device</para>
  287. /// </summary>
  288. public static bool GetDeviceBindingRevision(InputHandle_t inputHandle, out int pMajor, out int pMinor) {
  289. InteropHelp.TestIfAvailableClient();
  290. return NativeMethods.ISteamInput_GetDeviceBindingRevision(CSteamAPIContext.GetSteamInput(), inputHandle, out pMajor, out pMinor);
  291. }
  292. /// <summary>
  293. /// <para> Get the Steam Remote Play session ID associated with a device, or 0 if there is no session associated with it</para>
  294. /// <para> See isteamremoteplay.h for more information on Steam Remote Play sessions</para>
  295. /// </summary>
  296. public static uint GetRemotePlaySessionID(InputHandle_t inputHandle) {
  297. InteropHelp.TestIfAvailableClient();
  298. return NativeMethods.ISteamInput_GetRemotePlaySessionID(CSteamAPIContext.GetSteamInput(), inputHandle);
  299. }
  300. }
  301. }
  302. #endif // !DISABLESTEAMWORKS