CGEventSource.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. {
  2. * CGEventSource.h
  3. * CoreGraphics
  4. *
  5. * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
  6. *
  7. }
  8. { Pascal Translation: Peter N Lewis, <[email protected]>, August 2005 }
  9. {
  10. Modified for use with Free Pascal
  11. Version 200
  12. Please report any bugs to <[email protected]>
  13. }
  14. {$mode macpas}
  15. {$packenum 1}
  16. {$macro on}
  17. {$inline on}
  18. {$CALLING MWPASCAL}
  19. unit CGEventSource;
  20. interface
  21. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  22. {$setc GAP_INTERFACES_VERSION := $0200}
  23. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  24. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  25. {$endc}
  26. {$ifc defined CPUPOWERPC and defined CPUI386}
  27. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  28. {$endc}
  29. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  30. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  31. {$endc}
  32. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  33. {$setc __ppc__ := 1}
  34. {$elsec}
  35. {$setc __ppc__ := 0}
  36. {$endc}
  37. {$ifc not defined __i386__ and defined CPUI386}
  38. {$setc __i386__ := 1}
  39. {$elsec}
  40. {$setc __i386__ := 0}
  41. {$endc}
  42. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  43. {$error Conflicting definitions for __ppc__ and __i386__}
  44. {$endc}
  45. {$ifc defined __ppc__ and __ppc__}
  46. {$setc TARGET_CPU_PPC := TRUE}
  47. {$setc TARGET_CPU_X86 := FALSE}
  48. {$elifc defined __i386__ and __i386__}
  49. {$setc TARGET_CPU_PPC := FALSE}
  50. {$setc TARGET_CPU_X86 := TRUE}
  51. {$elsec}
  52. {$error Neither __ppc__ nor __i386__ is defined.}
  53. {$endc}
  54. {$setc TARGET_CPU_PPC_64 := FALSE}
  55. {$ifc defined FPC_BIG_ENDIAN}
  56. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  57. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  58. {$elifc defined FPC_LITTLE_ENDIAN}
  59. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  60. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  61. {$elsec}
  62. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  63. {$endc}
  64. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  65. {$setc CALL_NOT_IN_CARBON := FALSE}
  66. {$setc OLDROUTINENAMES := FALSE}
  67. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  68. {$setc OPAQUE_UPP_TYPES := TRUE}
  69. {$setc OTCARBONAPPLICATION := TRUE}
  70. {$setc OTKERNEL := FALSE}
  71. {$setc PM_USE_SESSION_APIS := TRUE}
  72. {$setc TARGET_API_MAC_CARBON := TRUE}
  73. {$setc TARGET_API_MAC_OS8 := FALSE}
  74. {$setc TARGET_API_MAC_OSX := TRUE}
  75. {$setc TARGET_CARBON := TRUE}
  76. {$setc TARGET_CPU_68K := FALSE}
  77. {$setc TARGET_CPU_MIPS := FALSE}
  78. {$setc TARGET_CPU_SPARC := FALSE}
  79. {$setc TARGET_OS_MAC := TRUE}
  80. {$setc TARGET_OS_UNIX := FALSE}
  81. {$setc TARGET_OS_WIN32 := FALSE}
  82. {$setc TARGET_RT_MAC_68881 := FALSE}
  83. {$setc TARGET_RT_MAC_CFM := FALSE}
  84. {$setc TARGET_RT_MAC_MACHO := TRUE}
  85. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  86. {$setc TYPE_BOOL := FALSE}
  87. {$setc TYPE_EXTENDED := FALSE}
  88. {$setc TYPE_LONGLONG := TRUE}
  89. uses MacTypes,CFBase,CFDate,CGRemoteOperation,CGEventTypes;
  90. {$ALIGN POWER}
  91. { Return the CFTypeID for CGEventSourceRefs. }
  92. function CGEventSourceGetTypeID: CFTypeID; external name '_CGEventSourceGetTypeID'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  93. {
  94. * Create a new CGEventSource
  95. *
  96. * The event source contains accumulated state related to event
  97. * generation and event posting, allowing for customized event
  98. * generation and processing.
  99. *
  100. * The CGEventSourceStateID refers to a global event state table.
  101. * These tables contain accumulated information on modifier flag state,
  102. * keyboard key state, mouse button state, and related internal parameters
  103. * placed in effect by posting events with associated sources.
  104. *
  105. * Two pre-existing tables are defined.
  106. *
  107. * The kCGEventSourceStateCombinedSessionState table reflects the combined state
  108. * of all event sources posting to this user login session. Mouse button,
  109. * keyboard state, and modifier flag state (derived from keyboard state)
  110. * are logically ORed together in this state table.
  111. *
  112. * The kCGEventSourceStateHIDSystemState table reflects the combined state
  113. * of all hardware event sources posting from the HID system. Mouse button,
  114. * keyboard state, and modifier flag state (derived from keyboard state)
  115. * for the hardware devices are logically ORed together in this state table.
  116. *
  117. * A program, or application posting from within a login session should use
  118. * the kCGEventSourceStateCombinedSessionState.
  119. *
  120. * A user space device driver interpreting hardware state and generating events
  121. * should use the kCGEventSourceStateHIDSystemState.
  122. *
  123. * Very specialized applications such as remote control programs may want to
  124. * generate and track event source state independent of other processes.
  125. * These programs should use the kCGEventSourceStatePrivate value in creating
  126. * their event source. An independent state table and unique CGEventSourceStateID
  127. * are created to track the event source's state. The independent sate table is owned
  128. * by the creating event source and released with it.
  129. *
  130. * If the CGEventSourceStateID from another CGEventSourceRef
  131. * is released while being used in a second CGEventSourceRef, the second source
  132. * will behave as if all keys and buttons on input devices are up in generating
  133. * new events from this source.
  134. *
  135. * Default behavior without an event source, that is, passing NULL to
  136. * CGEvent creation functions, is identical to using an unmodified
  137. * CGEventSource created with the kCGEventSourceStateCombinedSystemState
  138. * source state ID, if running within a login session, or using
  139. * kCGEventSourceStateHIDSystemState if running outside of a login session,
  140. * as in a daemon or user space device driver.
  141. *
  142. * Returns NULL if the specified event source is not a valid CGEventSourceStateID,
  143. * or is a private event source owned by another process,
  144. * or is not a member of the following enumeration.
  145. *
  146. * The returned object should be released with CFRelease when no longer needed.
  147. }
  148. function CGEventSourceCreate( sourceState: CGEventSourceStateID ): CGEventSourceRef; external name '_CGEventSourceCreate'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  149. {
  150. * Set and get the keyboard type to be used with this source
  151. * The value will be used with UCKeyTranslate() to drive keyboard translation
  152. }
  153. function CGEventSourceGetKeyboardType( source: CGEventSourceRef ): CGEventSourceKeyboardType; external name '_CGEventSourceGetKeyboardType'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  154. procedure CGEventSourceSetKeyboardType( source: CGEventSourceRef; keyboardType: CGEventSourceKeyboardType ); external name '_CGEventSourceSetKeyboardType'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  155. {
  156. * Return the event source state ID associated with the event source.
  157. * For event sources created with the kCGEventSourceStatePrivate
  158. * CGEventSourceStateID, this returns the actual CGEventSourceStateID
  159. * created for the CGEventSourceRef.
  160. *
  161. * The value returned may be passed to CGEventSourceCreate() to create a
  162. * second event source sharing the same state table. This may be useful,
  163. * for example, in creating seperate mouse and keyboard sources which share
  164. * a common private state.
  165. *
  166. * If the CGEventSourceStateID from another CGEventSourceRef
  167. * is released while being used in a second CGEventSourceRef, the second source
  168. * will behave as if all keys and buttons on input devices are up in generating
  169. * new events from this source.
  170. }
  171. function CGEventSourceGetSourceStateID( source: CGEventSourceRef ): CGEventSourceStateID; external name '_CGEventSourceGetSourceStateID'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  172. {
  173. * The state of an event source may be queried for specialized event processing
  174. * purposes.
  175. }
  176. function CGEventSourceButtonState( sourceState: CGEventSourceStateID; button: CGMouseButton ): CBool; external name '_CGEventSourceButtonState'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  177. function CGEventSourceKeyState( sourceState: CGEventSourceStateID; key: CGKeyCode ): CBool; external name '_CGEventSourceKeyState'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  178. function CGEventSourceFlagsState( sourceState: CGEventSourceStateID ): CGEventFlags; external name '_CGEventSourceFlagsState'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  179. {
  180. * Time since last event for an event source.
  181. *
  182. * The kCGAnyInputEventType eventType will report the last timestamp for any
  183. * input event, keyboard, mouse, or tablet. The various system and app
  184. * defined events do not contribute to this event type's time.
  185. *
  186. * Again, a program or application posting from within a login session should use
  187. * the kCGEventSourceStateCombinedSessionState.
  188. *
  189. * A user space device driver interpreting hardware state and generating events
  190. * should use the kCGEventSourceStateHIDSystemState.
  191. }
  192. function CGEventSourceSecondsSinceLastEventType( source: CGEventSourceStateID; eventType: CGEventType ): CFTimeInterval; external name '_CGEventSourceSecondsSinceLastEventType'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  193. {
  194. * Returns a count of events of different types seen since the window server started.
  195. *
  196. * Note that modifier keys produce kCGEventFlagsChanged events, not kCGEventKeyDown
  197. * events, and do so both on press and release.
  198. *
  199. * Please note that some keys on the keyboard are not implemented as keys,
  200. * but instead are USB button devices. We account for the ones we can see as
  201. * kCGEventKeyDown events. Where we don't get a different event for key-up, we
  202. * record both a key down and a key up.
  203. *
  204. * There is no guarantee that the number of key down and key up events will match
  205. * when all keyboard keys are up, due to the inconsistent nature of the USB button device keys.
  206. *
  207. * Key autorepeat events are not counted.
  208. *
  209. * Synthetic events posted into the system may also produce assymetric 'down' and 'up' event counts.
  210. *
  211. * Again, a program or application posting from within a login session should use
  212. * the kCGEventSourceStateCombinedSessionState.
  213. *
  214. * A user space device driver interpreting hardware state and generating events
  215. * should use the kCGEventSourceStateHIDSystemState.
  216. *
  217. }
  218. function CGEventSourceCounterForEventType( source: CGEventSourceStateID; evType: CGEventType ): UInt32; external name '_CGEventSourceCounterForEventType'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  219. {
  220. * Each event carries a payload of 64 bits of user specified data.
  221. * The values may be individually set per event using the
  222. * CGEventSetIntegerValueField() API, or may be set for all events
  223. * created by this event source using this API.
  224. * This mechanism is more convenient for uses such as vendor hardware IDs.
  225. }
  226. procedure CGEventSourceSetUserData( source: CGEventSourceRef; userData: SInt64 ); external name '_CGEventSourceSetUserData'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  227. function CGEventSourceGetUserData( source: CGEventSourceRef ): SInt64; external name '_CGEventSourceGetUserData'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  228. {
  229. * The CGRemoteOperation APIs (CoreGraphics/CGRemoteOperation.h) use an implicit event
  230. * source to affect system behavior on event posting. Here we expose the same mechanism
  231. * on a per event source basis. Default values are different than the remote operation API
  232. * exposes, based on developer feedback.
  233. }
  234. {
  235. * The system may optionally suppress local hardware events
  236. * from the keyboard and mouse during a short interval after
  237. * a program posts an event (see CGSetLocalEventsSuppressionInterval())
  238. * or while your program has a left mouse button down (mouse drag) in effect.
  239. *
  240. * Some classes of applications may want to disable events from some of the local hardware.
  241. * For example, an app may want to post only mouse events, and so may wish to permit local
  242. * keyboard hardware events to pass through while blocking local mouse events.
  243. * Set the event source to permit keyboard events
  244. * prior to creating the mouse event after which you want to get keyboard events.
  245. *
  246. * This interface lets an app specify a state (event suppression interval, or mouse drag), and
  247. * a mask of event categories to be passed through. The new filter state takes effect
  248. * with the next event your app posts that is created with this event source.
  249. *
  250. * The kCGEventSuppressionStateSuppressionInterval state allows one to set a filter that
  251. * permits local hardware mouse events, local keyboard events, both, or neither during the
  252. * specified short interval of time after your process posts an event created with this source.
  253. *
  254. * The kCGEventSuppressionStateRemoteMouseDrag state allows one to set a filter that
  255. * permits local hardware mouse events, local keyboard events, both, or neither during
  256. * the time that your event source has a left mouse button down (mouse drag) in effect.
  257. *
  258. * The default state for a CGEventSourceRef is to have all filtering off, so that local
  259. * hardware events are unaffected.
  260. *
  261. * When a user enters the 'Force Quit' keyboard attention sequence, Command-Option-Escape,
  262. * all local event supression filters in effect are disabled, and all local hardware
  263. * events are delivered as normal. This allows for recovery from unfortunate programming
  264. * errors.
  265. }
  266. procedure CGEventSourceSetLocalEventsFilterDuringSuppressionState( source: CGEventSourceRef; filter: CGEventFilterMask; state: CGEventSuppressionState ); external name '_CGEventSourceSetLocalEventsFilterDuringSuppressionState'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  267. function CGEventSourceGetLocalEventsFilterDuringSuppressionState( source: CGEventSourceRef; state: CGEventSuppressionState ): CGEventFilterMask; external name '_CGEventSourceGetLocalEventsFilterDuringSuppressionState'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  268. {
  269. * Set the period of time in seconds that specified local hardware events (keyboard or mouse)
  270. * may suppressed after posting a CGEventRef created with this source, if the event
  271. * source is set to apply the kCGEventSuppressionStateSuppressionInterval.
  272. *
  273. * Defaults to 0.25 second.
  274. }
  275. procedure CGEventSourceSetLocalEventsSuppressionInterval( source: CGEventSourceRef; seconds: CFTimeInterval ); external name '_CGEventSourceSetLocalEventsSuppressionInterval'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  276. function CGEventSourceGetLocalEventsSuppressionInterval( source: CGEventSourceRef ): CFTimeInterval; external name '_CGEventSourceGetLocalEventsSuppressionInterval'; (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
  277. end.