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