IOHIDEvent.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. IOHIDEvent.h ... Header for IOHIDEvent*** functions.
  3. Copyright (c) 2009 KennyTM~ <kennytm@gmail.com>
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without modification,
  6. are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright notice, this
  8. list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. * Neither the name of the KennyTM~ nor the names of its contributors may be
  13. used to endorse or promote products derived from this software without
  14. specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. // With reference to http://www.opensource.apple.com/source/IOHIDFamily/IOHIDFamily-308/IOHIDFamily/IOHIDEvent.h .
  27. #ifndef IOKIT_HID_IOHIDEVENT_H
  28. #define IOKIT_HID_IOHIDEVENT_H 1
  29. #include <libkern/OSTypes.h>
  30. #include <IOKit/IOTypes.h>
  31. #include <IOKit/hid/IOHIDEventTypes.h>
  32. #include <IOKit/hid/IOHIDEventData.h>
  33. #include <CoreFoundation/CoreFoundation.h>
  34. #if __cplusplus
  35. extern "C" {
  36. #endif
  37. typedef struct __IOHIDEvent
  38. #if 0
  39. {
  40. CFRuntimeBase base; // 0, 4
  41. AbsoluteTime _timeStamp; // 8, c
  42. int x10; // 10
  43. int x14; // 14
  44. IOOptionBits _options; // 18
  45. unsigned _typeMask; // 1c
  46. CFMutableArrayRef _children; // 20
  47. struct __IOHIDEvent* _parent; // 24
  48. size_t recordSize; // 28
  49. void record[];
  50. }
  51. #endif
  52. * IOHIDEventRef;
  53. #pragma mark -
  54. #pragma mark GetTypeID
  55. /*! @function IOHIDEventGetTypeID */
  56. CFTypeID IOHIDEventGetTypeID(void);
  57. #pragma mark -
  58. #pragma mark Generic creation functions
  59. IOHIDEventRef IOHIDEventCreateCopy(CFAllocatorRef allocator, IOHIDEventRef event);
  60. /*! @function IOHIDEventCreate
  61. @abstract Create an IOHIDEvent.
  62. @discussion All event-specific parameters are zeroed. */
  63. IOHIDEventRef IOHIDEventCreate(CFAllocatorRef allocator, IOHIDEventType type, AbsoluteTime timeStamp, IOOptionBits options);
  64. CFMutableDataRef IOHIDEventCreateData(CFAllocatorRef allocator, IOHIDEventRef event);
  65. IOHIDEventRef IOHIDEventCreateWithData(CFAllocatorRef allocator, CFDataRef data);
  66. #pragma mark -
  67. #pragma mark Predefined creation functions
  68. IOHIDEventRef IOHIDEventCreateProgressEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  69. uint32_t eventType, IOHIDFloat level, IOOptionBits options);
  70. IOHIDEventRef IOHIDEventCreateVendorDefinedEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  71. uint16_t usagePage, uint16_t usage, uint32_t version, const uint8_t* data, uint32_t length, IOOptionBits options);
  72. IOHIDEventRef IOHIDEventCreateSwipeEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDSwipeMask swipeMask, IOOptionBits options);
  73. /*! @function IOHIDEventCreateDigitizerEvent
  74. @abstract Create a digitizer event. You should use the more specialized methods instead. */
  75. IOHIDEventRef IOHIDEventCreateDigitizerEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDDigitizerTransducerType type,
  76. uint32_t index, uint32_t identity, uint32_t eventMask, uint32_t buttonMask,
  77. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat barrelPressure,
  78. Boolean range, Boolean touch, IOOptionBits options);
  79. IOHIDEventRef IOHIDEventCreateDigitizerFingerEventWithQuality(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  80. uint32_t index, uint32_t identity, uint32_t eventMask,
  81. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat twist,
  82. IOHIDFloat minorRadius, IOHIDFloat majorRadius, IOHIDFloat quality, IOHIDFloat density, IOHIDFloat irregularity,
  83. Boolean range, Boolean touch, IOOptionBits options);
  84. /*! @function IOHIDEventCreateDigitizerFingerEvent
  85. @abstract Create a finger digitizer event with default qualities.
  86. @discussion The default qualities are:
  87. - minorRadius = 5 mm,
  88. - majorRadius = 5 mm,
  89. - quality = 1,
  90. - density = 1,
  91. - irregularity = 1. */
  92. IOHIDEventRef IOHIDEventCreateDigitizerFingerEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  93. uint32_t index, uint32_t identity, uint32_t eventMask,
  94. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat twist,
  95. Boolean range, Boolean touch, IOOptionBits options);
  96. IOHIDEventRef IOHIDEventCreateDigitizerStylusEventWithPolarOrientation(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  97. uint32_t index, uint32_t identity, uint32_t eventMask, uint32_t buttonMask,
  98. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat barrelPressure,
  99. IOHIDFloat twist, IOHIDFloat altitude, IOHIDFloat azimuth,
  100. Boolean range, Boolean invert, IOOptionBits options);
  101. /*! @function IOHIDEventCreateDigitizerStylusEvent
  102. @discussion Same as IOHIDEventCreateDigitizerStylusEventWithPolarOrientation? */
  103. IOHIDEventRef IOHIDEventCreateDigitizerStylusEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  104. uint32_t index, uint32_t identity, uint32_t eventMask, uint32_t buttonMask,
  105. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat barrelPressure,
  106. IOHIDFloat twist, IOHIDFloat altitude, IOHIDFloat azimuth,
  107. Boolean range, Boolean invert, IOOptionBits options);
  108. IOHIDEventRef IOHIDEventCreateProximtyEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDProximityDetectionMask detectionMask, IOOptionBits options);
  109. #define IOHIDEventCreateProximityEvent IOHIDEventCreateProximtyEvent
  110. IOHIDEventRef IOHIDEventCreateAmbientLightSensorEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat level, IOOptionBits options);
  111. /*! @function IOHIDEventCreateMouseEvent
  112. @abstract Create an mouse event, with pressure of 1.0. */
  113. IOHIDEventRef IOHIDEventCreateMouseEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  114. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, uint32_t buttonMask, IOOptionBits options);
  115. /*! @function IOHIDEventCreateMouseEventWithPressure
  116. @abstract Create an mouse event with pressure.
  117. @discussion The mouse is considered clicked when the pressure is > 0.15. */
  118. IOHIDEventRef IOHIDEventCreateMouseEventWithPressure(CFAllocatorRef allocator, AbsoluteTime timeStamp,
  119. IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, uint32_t buttonMask, IOHIDFloat pressure, IOOptionBits options);
  120. /*! @function IOHIDEventCreateButtonEvent
  121. @abstract Create an button event, with pressure of 1.0. */
  122. IOHIDEventRef IOHIDEventCreateButtonEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, uint32_t buttonMask, IOOptionBits options);
  123. /*! @function IOHIDEventCreateButtonEventWithPressure
  124. @abstract Create an button event with pressure.
  125. @discussion The button is considered pressed when the pressure is > 0.15. */
  126. IOHIDEventRef IOHIDEventCreateButtonEventWithPressure(CFAllocatorRef allocator, AbsoluteTime timeStamp, uint32_t buttonMask, IOHIDFloat pressure, IOOptionBits options);
  127. IOHIDEventRef IOHIDEventCreateKeyboardEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, uint16_t usagePage, uint16_t usage, Boolean down, IOHIDEventOptionBits flags);
  128. IOHIDEventRef IOHIDEventCreateAccelerometerEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  129. IOHIDEventRef IOHIDEventCreatePolarOrientationEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  130. IOHIDEventRef IOHIDEventCreateOrientationEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  131. IOHIDEventRef IOHIDEventCreateVelocityEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  132. IOHIDEventRef IOHIDEventCreateScaleEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  133. IOHIDEventRef IOHIDEventCreateScrollEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  134. IOHIDEventRef IOHIDEventCreateRotationEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  135. IOHIDEventRef IOHIDEventCreateTranslationEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOOptionBits options);
  136. #pragma mark -
  137. #pragma mark Accessors
  138. IOHIDEventType IOHIDEventGetType(IOHIDEventRef event);
  139. AbsoluteTime IOHIDEventGetTimeStamp(IOHIDEventRef event);
  140. void IOHIDEventSetTimeStamp(IOHIDEventRef event, AbsoluteTime timeStamp);
  141. uint32_t IOHIDEventGetEventFlags(IOHIDEventRef event);
  142. void IOHIDEventSetEventFlags(IOHIDEventRef event, uint32_t eventFlags);
  143. Boolean IOHIDEventIsAbsolute(IOHIDEventRef event);
  144. IOHIDEventRef IOHIDEventGetParent(IOHIDEventRef event);
  145. CFArrayRef IOHIDEventGetChildren(IOHIDEventRef event);
  146. void IOHIDEventGetVendorDefinedData(IOHIDEventRef event, uint32_t* length, uint8_t** data);
  147. #pragma mark -
  148. #pragma mark Subevents
  149. /*! @function IOHIDEventGetEventWithOptions
  150. @abstract Get the deepest event that bears the specified type and matches the options.
  151. @discussion If any of the top 4 bits of options is set (i.e. (options & 0xF0000000) != 0), the children of this event will not be checked. */
  152. IOHIDEventRef IOHIDEventGetEventWithOptions(IOHIDEventRef event, IOHIDEventType type, IOOptionBits options);
  153. /*! @function IOHIDEventGetEvent
  154. @abstract Get the event that bears the specified type.
  155. @discussion Equivalent to IOHIDEventGetEventWithOptions(event, type, 0xF0000000); */
  156. IOHIDEventRef IOHIDEventGetEvent(IOHIDEventRef event, IOHIDEventType type);
  157. void IOHIDEventSetFloatValueWithOptions(IOHIDEventRef event, IOHIDEventField field, IOHIDFloat value, IOOptionBits options);
  158. void IOHIDEventSetFloatValue(IOHIDEventRef event, IOHIDEventField field, IOHIDFloat value);
  159. void IOHIDEventSetIntegerValueWithOptions(IOHIDEventRef event, IOHIDEventField field, int value, IOOptionBits options);
  160. void IOHIDEventSetIntegerValue(IOHIDEventRef event, IOHIDEventField field, int value);
  161. void IOHIDEventSetPositionWithOptions(IOHIDEventRef event, IOHIDEventField field, IOHID3DPoint position, IOOptionBits options);
  162. void IOHIDEventSetPosition(IOHIDEventRef event, IOHIDEventField field, IOHID3DPoint position);
  163. IOHIDFloat IOHIDEventGetFloatValueWithOptions(IOHIDEventRef event, IOHIDEventField field, IOOptionBits options);
  164. IOHIDFloat IOHIDEventGetFloatValue(IOHIDEventRef event, IOHIDEventField field);
  165. int IOHIDEventGetIntegerValueWithOptions(IOHIDEventRef event, IOHIDEventField field, IOOptionBits options);
  166. int IOHIDEventGetIntegerValue(IOHIDEventRef event, IOHIDEventField field);
  167. IOHID3DPoint IOHIDEventGetPositionWithOptions(IOHIDEventRef event, IOHIDEventField field, IOOptionBits options);
  168. IOHID3DPoint IOHIDEventGetPosition(IOHIDEventRef event, IOHIDEventField field);
  169. /*! @function IOHIDEventConformsToWithOptions
  170. @abstract Returns if the event or any of its children bears the specified type and options.
  171. @discussion If any of the top 4 bits of options is set (i.e. (options & 0xF0000000) != 0), the children of this event will not be checked. */
  172. Boolean IOHIDEventConformsToWithOptions(IOHIDEventRef event, IOHIDEventType type, IOOptionBits options);
  173. /*! @function IOHIDEventConformsTo
  174. @abstract Returns if the event bears the specified type.
  175. @discussion Equivalent to IOHIDEventConformsToWithOptions(event, type, 0xF0000000); */
  176. Boolean IOHIDEventConformsTo(IOHIDEventRef event, IOHIDEventType type);
  177. void IOHIDEventRemoveEvent(IOHIDEventRef event, IOHIDEventRef childEvent);
  178. void IOHIDEventAppendEvent(IOHIDEventRef event, IOHIDEventRef childEvent);
  179. #if __cplusplus
  180. }
  181. #endif
  182. #endif