PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/SharpDX.DirectInput/DeviceProperties.cs

https://github.com/PlehXP/SharpDX
C# | 262 lines | 103 code | 30 blank | 129 comment | 1 complexity | 903e7175a70c8f6a8cc7ce273c2b259b MD5 | raw file
Possible License(s): AGPL-3.0, GPL-2.0, CC-BY-SA-3.0, Unlicense
  1. // Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. using System;
  21. namespace SharpDX.DirectInput
  22. {
  23. /// <summary>
  24. /// Properties for a <see cref="Device"/>.
  25. /// </summary>
  26. public partial class DeviceProperties : PropertyAccessor
  27. {
  28. internal DeviceProperties(Device device) : base(device, 0, PropertyHowType.Device)
  29. {
  30. }
  31. /// <summary>
  32. /// Gets the key code for a keyboard key. An exception is raised if the property cannot resolve specialized keys on USB keyboards because they do not exist in scan code form. For all other failures, an exception is also returned.
  33. /// </summary>
  34. /// <param name="key">The key id.</param>
  35. /// <returns>The key code</returns>
  36. public int GetKeyCode(Key key)
  37. {
  38. // TODO check BYid
  39. return GetInt(PropertyGuids.Scancode, (int) key);
  40. }
  41. /// <summary>
  42. /// Gets the localized key name for a keyboard key. Using this property on devices other than a keyboard will return unexpected names.
  43. /// </summary>
  44. /// <param name="key">The key.</param>
  45. /// <returns></returns>
  46. public string GetKeyName(Key key)
  47. {
  48. // TODO check BYid
  49. return GetString(PropertyGuids.Keyname, (int)key);
  50. }
  51. // ApplicationData are not working, seems to be a bug in DirectInput
  52. ///// <summary>
  53. ///// Gets or sets the application-defined value associated with an in-game action.
  54. ///// </summary>
  55. ///// <value>The application data.</value>
  56. //public object ApplicationData
  57. //{
  58. // get { return GetObject(PropertyGuids.Appdata); }
  59. // set { SetObject(PropertyGuids.Appdata, value); }
  60. //}
  61. /// <summary>
  62. /// Gets or sets a value indicating whether device objects are self centering.
  63. /// </summary>
  64. /// <value><c>true</c> if device objects are self centering; otherwise, <c>false</c>.</value>
  65. public bool AutoCenter
  66. {
  67. get { return GetInt(PropertyGuids.Autocenter) != 0; }
  68. set { Set(PropertyGuids.Autocenter, value ? 1 : 0); }
  69. }
  70. /// <summary>
  71. /// Gets or sets the axis mode.
  72. /// </summary>
  73. /// <value>The axis mode.</value>
  74. public DeviceAxisMode AxisMode
  75. {
  76. get { return (DeviceAxisMode) GetInt(PropertyGuids.Axismode); }
  77. set { Set(PropertyGuids.Axismode, (int) value); }
  78. }
  79. /// <summary>
  80. /// Gets or sets the input buffer size. The buffer size determines the amount of data that the buffer can hold between calls to the <see cref="Device.GetDeviceData"/> method before data is lost. You can set this value to 0 to indicate that the application does not read buffered data from the device. If the buffer size is too large for the device to support it, then the largest possible buffer size is set. However, this property always returns the buffer size set using the <see cref="BufferSize"/> property, even if the buffer cannot be supported because it is too large.
  81. /// </summary>
  82. /// <value>The size of the buffer.</value>
  83. public int BufferSize
  84. {
  85. get { return GetInt(PropertyGuids.BufferSize); }
  86. set { Set(PropertyGuids.BufferSize, value); }
  87. }
  88. /// <summary>
  89. /// Gets the class GUID for the device. This property lets advanced applications perform operations on a human interface device that are not supported by DirectInput.
  90. /// </summary>
  91. /// <value>The class GUID.</value>
  92. public Guid ClassGuid
  93. {
  94. get { return GetGuid(PropertyGuids.Guidandpath); }
  95. }
  96. /// <summary>
  97. /// Gets or sets the dead zone of a joystick, in the range from 0 through 10,000, where 0 indicates that there is no dead zone, 5,000 indicates that the dead zone extends over 50 percent of the physical range of the axis on both sides of center, and 10,000 indicates that the entire physical range of the axis is dead. When the axis is within the dead zone, it is reported as being at the center of its range.
  98. /// </summary>
  99. /// <value>The dead zone.</value>
  100. public int DeadZone
  101. {
  102. get { return GetInt(PropertyGuids.Deadzone); }
  103. set { Set(PropertyGuids.Deadzone, value); }
  104. }
  105. /// <summary>
  106. /// Gets or sets the force feedback gain of the device.
  107. /// The gain value is applied to all effects created on the device. The value is an integer in the range from 0 through 10,000, specifying the amount by which effect magnitudes should be scaled for the device. For example, a value of 10,000 indicates that all effect magnitudes are to be taken at face value. A value of 9,000 indicates that all effect magnitudes are to be reduced to 90 percent of their nominal magnitudes.
  108. /// DirectInput always checks the gain value before setting the gain property. If the gain is outside of the range (less than zero or greater than 10,000), setting this property will raise an exception. Otherwise, no exception if successful, even if the device does not support force feedback.
  109. /// Setting a gain value is useful when an application wants to scale down the strength of all force-feedback effects uniformly, based on user preferences.
  110. /// Unlike other properties, the gain can be set when the device is in an acquired state.
  111. /// </summary>
  112. /// <value>The force feedback gain.</value>
  113. public int ForceFeedbackGain
  114. {
  115. get { return GetInt(PropertyGuids.Ffgain); }
  116. set { Set(PropertyGuids.Ffgain, value); }
  117. }
  118. /// <summary>
  119. /// Gets the input granularity. Granularity represents the smallest distance over which the object reports movement. Most axis objects have a granularity of one; that is, all values are possible. Some axes have a larger granularity. For example, the wheel axis on a mouse can have a granularity of 20; that is, all reported changes in position are multiples of 20. In other words, when the user turns the wheel slowly, the device reports a position of 0, then 20, then 40, and so on. This is a read-only property.
  120. /// </summary>
  121. /// <value>The granularity.</value>
  122. public int Granularity
  123. {
  124. get { return GetInt(PropertyGuids.Granularity); }
  125. }
  126. /// <summary>
  127. /// Gets or sets the friendly instance name of the device.
  128. /// This property exists for advanced applications that want to change the friendly instance name of a device (as returned in the tszInstanceName member of the <see cref="DeviceInstance"/> structure) to distinguish it from similar devices that are plugged in simultaneously. Most applications should have no need to change the friendly name.
  129. /// </summary>
  130. /// <value>The name of the instance.</value>
  131. public string InstanceName
  132. {
  133. get { return GetString(PropertyGuids.InstanceName); }
  134. set { Set(PropertyGuids.InstanceName, value); }
  135. }
  136. /// <summary>
  137. /// Gets the device interface path for the device. This property lets advanced applications perform operations on a human interface device that are not supported by DirectInput.
  138. /// </summary>
  139. /// <value>The interface path.</value>
  140. public string InterfacePath
  141. {
  142. get { return GetPath(PropertyGuids.Guidandpath); }
  143. }
  144. /// <summary>
  145. /// Gets the instance number of a joystick. This property is not implemented for the mouse or keyboard.
  146. /// </summary>
  147. /// <value>The joystick id.</value>
  148. public int JoystickId
  149. {
  150. get { return GetInt(PropertyGuids.Joystickid); }
  151. }
  152. /// <summary>
  153. /// Gets the memory load for the device. This setting applies to the entire device, rather than to any particular object. The retrieved value is in the range from 0 through 100, indicating the percentage of device memory in use. The device must be acquired in exclusive mode. If it is not, the method will fail with an exception.
  154. /// </summary>
  155. /// <value>The memory load.</value>
  156. public int MemoryLoad
  157. {
  158. get { return GetInt(PropertyGuids.Ffload); }
  159. }
  160. /// <summary>
  161. /// Gets the human-readable display name of the port to which this device is connected. Not generally used by applications.
  162. /// </summary>
  163. /// <value>The human-readable display name of the port to which this device is connected.</value>
  164. public string PortDisplayName
  165. {
  166. get { return GetPath(PropertyGuids.GetPortdisplayname); }
  167. }
  168. /// <summary>
  169. /// Gets the vendor identity (ID) and product ID of a HID device. This property is of type int and contains both values. These two short values are combined. This property applies to the entire device, rather than to any particular object.
  170. /// </summary>
  171. /// <value>The product id.</value>
  172. public int ProductId
  173. {
  174. get { return (GetInt(PropertyGuids.Vidpid) >> 16) & 0xFFFF; }
  175. }
  176. /// <summary>
  177. /// Gets or sets the friendly product name of the device.
  178. /// This property exists for advanced applications that want to change the friendly product name of a device (as returned in the tszProductName member of the <see cref="DeviceInstance"/> structure) to distinguish it from similar devices which are plugged in simultaneously. Most applications should have no need to change the friendly name.
  179. /// This setting applies to the entire device.
  180. /// Setting the product name is only useful for changing the user-defined name of an analog joystick on Microsoft Windows 98, Windows 2000, and Windows Millennium Edition (Windows Me) computers. In other cases, attempting to set this property will still return ok. However, the name is not stored in a location used by the getter of this property.
  181. /// </summary>
  182. /// <value>The name of the product.</value>
  183. public string ProductName
  184. {
  185. get { return GetString(PropertyGuids.Productname); }
  186. set { Set(PropertyGuids.Productname, value); }
  187. }
  188. /// <summary>
  189. /// Gets or sets the range of values an object can possibly report.
  190. /// </summary>
  191. /// <value>The range.</value>
  192. /// <remarks>For some devices, this is a read-only property.</remarks>
  193. public InputRange Range
  194. {
  195. get { return GetRange(PropertyGuids.Range); }
  196. set { Set(PropertyGuids.Range, value);}
  197. }
  198. /// <summary>
  199. /// Gets or sets the saturation zones of a joystick, in the range from 0 through 10,000. The saturation level is the point at which the axis is considered to be at its most extreme position. For example, if the saturation level is set to 9,500, the axis reaches the extreme of its range when it has moved 95 percent of the physical distance from its center position (or from the dead zone).
  200. /// </summary>
  201. /// <value>The saturation.</value>
  202. public int Saturation
  203. {
  204. get { return GetInt(PropertyGuids.Saturation); }
  205. set { Set(PropertyGuids.Saturation, value); }
  206. }
  207. /// <summary>
  208. /// Gets the type name of a device. For most game controllers, this is the registry key name under REGSTR_PATH_JOYOEM from which static device settings can be retrieved, but predefined joystick types have special names consisting of a number sign (&Sharp;) followed by a character dependent on the type. This value might not be available for all devices.
  209. /// </summary>
  210. /// <value>The name of the type.</value>
  211. public string TypeName
  212. {
  213. get { return GetPath(PropertyGuids.Typename); }
  214. }
  215. /// <summary>
  216. /// Gets the user name for a user currently assigned to a device. User names are set by calling <see cref="Device.SetActionMap"/>. If no user name is set, the method throws an exception.
  217. /// </summary>
  218. /// <value>The name of the user.</value>
  219. public string UserName
  220. {
  221. get { return GetPath(PropertyGuids.Username); }
  222. }
  223. /// <summary>
  224. /// Gets the vendor identity (ID) and product ID of a HID device. This property is of type int and contains both values. These two short values are combined. This property applies to the entire device, rather than to any particular object.
  225. /// </summary>
  226. /// <value>The product id.</value>
  227. public int VendorId
  228. {
  229. get { return GetInt(PropertyGuids.Vidpid) & 0xFFFF; }
  230. }
  231. }
  232. }