CGEvent.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. { CoreGraphics - CGEvent.h
  2. * Copyright (c) 2004-2008 Apple Inc.
  3. * All rights reserved. }
  4. { Pascal Translation: Peter N Lewis, <[email protected]>, August 2005 }
  5. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2009 }
  6. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2012 }
  7. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, August 2015 }
  8. {
  9. Modified for use with Free Pascal
  10. Version 308
  11. Please report any bugs to <[email protected]>
  12. }
  13. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  14. {$mode macpas}
  15. {$modeswitch cblocks}
  16. {$packenum 1}
  17. {$macro on}
  18. {$inline on}
  19. {$calling mwpascal}
  20. unit CGEvent;
  21. interface
  22. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  23. {$setc GAP_INTERFACES_VERSION := $0308}
  24. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  25. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  26. {$endc}
  27. {$ifc defined CPUPOWERPC and defined CPUI386}
  28. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  29. {$endc}
  30. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  31. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  32. {$endc}
  33. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  34. {$setc __ppc__ := 1}
  35. {$elsec}
  36. {$setc __ppc__ := 0}
  37. {$endc}
  38. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  39. {$setc __ppc64__ := 1}
  40. {$elsec}
  41. {$setc __ppc64__ := 0}
  42. {$endc}
  43. {$ifc not defined __i386__ and defined CPUI386}
  44. {$setc __i386__ := 1}
  45. {$elsec}
  46. {$setc __i386__ := 0}
  47. {$endc}
  48. {$ifc not defined __x86_64__ and defined CPUX86_64}
  49. {$setc __x86_64__ := 1}
  50. {$elsec}
  51. {$setc __x86_64__ := 0}
  52. {$endc}
  53. {$ifc not defined __arm__ and defined CPUARM}
  54. {$setc __arm__ := 1}
  55. {$elsec}
  56. {$setc __arm__ := 0}
  57. {$endc}
  58. {$ifc not defined __arm64__ and defined CPUAARCH64}
  59. {$setc __arm64__ := 1}
  60. {$elsec}
  61. {$setc __arm64__ := 0}
  62. {$endc}
  63. {$ifc defined cpu64}
  64. {$setc __LP64__ := 1}
  65. {$elsec}
  66. {$setc __LP64__ := 0}
  67. {$endc}
  68. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  69. {$error Conflicting definitions for __ppc__ and __i386__}
  70. {$endc}
  71. {$ifc defined __ppc__ and __ppc__}
  72. {$setc TARGET_CPU_PPC := TRUE}
  73. {$setc TARGET_CPU_PPC64 := FALSE}
  74. {$setc TARGET_CPU_X86 := FALSE}
  75. {$setc TARGET_CPU_X86_64 := FALSE}
  76. {$setc TARGET_CPU_ARM := FALSE}
  77. {$setc TARGET_CPU_ARM64 := FALSE}
  78. {$setc TARGET_OS_MAC := TRUE}
  79. {$setc TARGET_OS_IPHONE := FALSE}
  80. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  81. {$setc TARGET_OS_EMBEDDED := FALSE}
  82. {$elifc defined __ppc64__ and __ppc64__}
  83. {$setc TARGET_CPU_PPC := FALSE}
  84. {$setc TARGET_CPU_PPC64 := TRUE}
  85. {$setc TARGET_CPU_X86 := FALSE}
  86. {$setc TARGET_CPU_X86_64 := FALSE}
  87. {$setc TARGET_CPU_ARM := FALSE}
  88. {$setc TARGET_CPU_ARM64 := FALSE}
  89. {$setc TARGET_OS_MAC := TRUE}
  90. {$setc TARGET_OS_IPHONE := FALSE}
  91. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  92. {$setc TARGET_OS_EMBEDDED := FALSE}
  93. {$elifc defined __i386__ and __i386__}
  94. {$setc TARGET_CPU_PPC := FALSE}
  95. {$setc TARGET_CPU_PPC64 := FALSE}
  96. {$setc TARGET_CPU_X86 := TRUE}
  97. {$setc TARGET_CPU_X86_64 := FALSE}
  98. {$setc TARGET_CPU_ARM := FALSE}
  99. {$setc TARGET_CPU_ARM64 := FALSE}
  100. {$ifc defined iphonesim}
  101. {$setc TARGET_OS_MAC := FALSE}
  102. {$setc TARGET_OS_IPHONE := TRUE}
  103. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  104. {$elsec}
  105. {$setc TARGET_OS_MAC := TRUE}
  106. {$setc TARGET_OS_IPHONE := FALSE}
  107. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  108. {$endc}
  109. {$setc TARGET_OS_EMBEDDED := FALSE}
  110. {$elifc defined __x86_64__ and __x86_64__}
  111. {$setc TARGET_CPU_PPC := FALSE}
  112. {$setc TARGET_CPU_PPC64 := FALSE}
  113. {$setc TARGET_CPU_X86 := FALSE}
  114. {$setc TARGET_CPU_X86_64 := TRUE}
  115. {$setc TARGET_CPU_ARM := FALSE}
  116. {$setc TARGET_CPU_ARM64 := FALSE}
  117. {$ifc defined iphonesim}
  118. {$setc TARGET_OS_MAC := FALSE}
  119. {$setc TARGET_OS_IPHONE := TRUE}
  120. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  121. {$elsec}
  122. {$setc TARGET_OS_MAC := TRUE}
  123. {$setc TARGET_OS_IPHONE := FALSE}
  124. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  125. {$endc}
  126. {$setc TARGET_OS_EMBEDDED := FALSE}
  127. {$elifc defined __arm__ and __arm__}
  128. {$setc TARGET_CPU_PPC := FALSE}
  129. {$setc TARGET_CPU_PPC64 := FALSE}
  130. {$setc TARGET_CPU_X86 := FALSE}
  131. {$setc TARGET_CPU_X86_64 := FALSE}
  132. {$setc TARGET_CPU_ARM := TRUE}
  133. {$setc TARGET_CPU_ARM64 := FALSE}
  134. {$setc TARGET_OS_MAC := FALSE}
  135. {$setc TARGET_OS_IPHONE := TRUE}
  136. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  137. {$setc TARGET_OS_EMBEDDED := TRUE}
  138. {$elifc defined __arm64__ and __arm64__}
  139. {$setc TARGET_CPU_PPC := FALSE}
  140. {$setc TARGET_CPU_PPC64 := FALSE}
  141. {$setc TARGET_CPU_X86 := FALSE}
  142. {$setc TARGET_CPU_X86_64 := FALSE}
  143. {$setc TARGET_CPU_ARM := FALSE}
  144. {$setc TARGET_CPU_ARM64 := TRUE}
  145. {$ifc defined ios}
  146. {$setc TARGET_OS_MAC := FALSE}
  147. {$setc TARGET_OS_IPHONE := TRUE}
  148. {$setc TARGET_OS_EMBEDDED := TRUE}
  149. {$elsec}
  150. {$setc TARGET_OS_MAC := TRUE}
  151. {$setc TARGET_OS_IPHONE := FALSE}
  152. {$setc TARGET_OS_EMBEDDED := FALSE}
  153. {$endc}
  154. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  155. {$elsec}
  156. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  157. {$endc}
  158. {$ifc defined __LP64__ and __LP64__ }
  159. {$setc TARGET_CPU_64 := TRUE}
  160. {$elsec}
  161. {$setc TARGET_CPU_64 := FALSE}
  162. {$endc}
  163. {$ifc defined FPC_BIG_ENDIAN}
  164. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  165. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  166. {$elifc defined FPC_LITTLE_ENDIAN}
  167. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  168. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  169. {$elsec}
  170. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  171. {$endc}
  172. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  173. {$setc CALL_NOT_IN_CARBON := FALSE}
  174. {$setc OLDROUTINENAMES := FALSE}
  175. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  176. {$setc OPAQUE_UPP_TYPES := TRUE}
  177. {$setc OTCARBONAPPLICATION := TRUE}
  178. {$setc OTKERNEL := FALSE}
  179. {$setc PM_USE_SESSION_APIS := TRUE}
  180. {$setc TARGET_API_MAC_CARBON := TRUE}
  181. {$setc TARGET_API_MAC_OS8 := FALSE}
  182. {$setc TARGET_API_MAC_OSX := TRUE}
  183. {$setc TARGET_CARBON := TRUE}
  184. {$setc TARGET_CPU_68K := FALSE}
  185. {$setc TARGET_CPU_MIPS := FALSE}
  186. {$setc TARGET_CPU_SPARC := FALSE}
  187. {$setc TARGET_OS_UNIX := FALSE}
  188. {$setc TARGET_OS_WIN32 := FALSE}
  189. {$setc TARGET_RT_MAC_68881 := FALSE}
  190. {$setc TARGET_RT_MAC_CFM := FALSE}
  191. {$setc TARGET_RT_MAC_MACHO := TRUE}
  192. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  193. {$setc TYPE_BOOL := FALSE}
  194. {$setc TYPE_EXTENDED := FALSE}
  195. {$setc TYPE_LONGLONG := TRUE}
  196. uses MacTypes,CFBase,CFData,CFMachPort,CGBase,CGDirectDisplay,CGEventTypes,CGGeometry,CGErrors,CGRemoteOperation,CGEventSource;
  197. {$endc} {not MACOSALLINCLUDE}
  198. {$ALIGN POWER}
  199. {$ifc TARGET_OS_MAC}
  200. { Return the type identifier for the opaque type `CGEventRef'. }
  201. function CGEventGetTypeID: CFTypeID; external name '_CGEventGetTypeID';
  202. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  203. { Return a new event using the event source `source'. If `source' is NULL,
  204. the default source is used. }
  205. function CGEventCreate( source: CGEventSourceRef ): CGEventRef; external name '_CGEventCreate';
  206. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  207. { Return a "flattened" data representation of an event. }
  208. function CGEventCreateData( allocator: CFAllocatorRef; event: CGEventRef ): CFDataRef; external name '_CGEventCreateData';
  209. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  210. { Return an event created from a "flattened" data representation of the
  211. event. }
  212. function CGEventCreateFromData( allocator: CFAllocatorRef; data: CFDataRef ): CGEventRef; external name '_CGEventCreateFromData';
  213. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  214. { Return a new mouse event.
  215. The event source may be taken from another event, or may be NULL.
  216. `mouseType' should be one of the mouse event types. `mouseCursorPosition'
  217. should be the position of the mouse cursor in global coordinates.
  218. `mouseButton' should be the button that's changing state; `mouseButton'
  219. is ignored unless `mouseType' is one of `kCGEventOtherMouseDown',
  220. `kCGEventOtherMouseDragged', or `kCGEventOtherMouseUp'.
  221. The current implemementation of the event system supports a maximum of
  222. thirty-two buttons. Mouse button 0 is the primary button on the mouse.
  223. Mouse button 1 is the secondary mouse button (right). Mouse button 2 is
  224. the center button, and the remaining buttons are in USB device order. }
  225. function CGEventCreateMouseEvent( source: CGEventSourceRef; mouseType: CGEventType; mouseCursorPosition: CGPoint; mouseButton: CGMouseButton ): CGEventRef; external name '_CGEventCreateMouseEvent';
  226. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  227. { Return a new keyboard event.
  228. The event source may be taken from another event, or may be NULL. Based
  229. on the virtual key code values entered, the appropriate key down, key up,
  230. or flags changed events are generated.
  231. All keystrokes needed to generate a character must be entered, including
  232. SHIFT, CONTROL, OPTION, and COMMAND keys. For example, to produce a 'Z',
  233. the SHIFT key must be down, the 'z' key must go down, and then the SHIFT
  234. and 'z' key must be released:
  235. CGEventCreateKeyboardEvent(source, (CGKeyCode)56, true); // shift down
  236. CGEventCreateKeyboardEvent(source, (CGKeyCode) 6, true); // 'z' down
  237. CGEventCreateKeyboardEvent(source, (CGKeyCode) 6, false); // 'z' up
  238. CGEventCreateKeyboardEvent(source, (CGKeyCode)56, false); // 'shift up }
  239. function CGEventCreateKeyboardEvent( source: CGEventSourceRef; virtualKey: CGKeyCode; keyDown: CBool ): CGEventRef; external name '_CGEventCreateKeyboardEvent';
  240. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  241. { Return a new scrollwheel event.
  242. The event source may be taken from another event, or may be NULL. The
  243. scrolling units may be specified in lines using `kCGScrollEventUnitLine'
  244. or in pixels using `kCGScrollEventUnitPixel'. `kCGScrollEventUnitPixel'
  245. will produce an event that most applications interpret as a smooth
  246. scrolling event.
  247. One or more wheels must be specified. The current implementation supports
  248. up to three wheels.
  249. Every scrollwheel event can be interpreted to be scrolling by pixel or by
  250. line. The scale between the two is about 10 pixels per line by default.
  251. The scale can be altered by setting a custom value for the event source,
  252. using `CGEventSourceSetPixelsPerLine'. }
  253. function CGEventCreateScrollWheelEvent( source: CGEventSourceRef; units: CGScrollEventUnit; wheelCount: UInt32; wheel1: SInt32; ... ): CGEventRef; external name '_CGEventCreateScrollWheelEvent';
  254. (* CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA) *)
  255. { Return a copy of `event'. }
  256. function CGEventCreateCopy( event: CGEventRef ): CGEventRef; external name '_CGEventCreateCopy';
  257. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  258. {
  259. * CFRetain() and CFRelease() may be used to retain and release CGEventRefs.
  260. }
  261. function CGEventGetSource( event: CGEventRef ): CGEventSourceRef; external name '_CGEventGetSource'; (* DEPRECATED_IN_MAC_OS_X_VERSION_10_4_AND_LATER *)
  262. { Return an event source created from an existing event.
  263. Event filters may use the event source to generate events that are
  264. compatible with an event being filtered.
  265. Note that `CGEventCreateSourceFromEvent' may return NULL if the event
  266. was generated with a private CGEventSourceStateID owned by another
  267. process. Such events should be filtered based on the public state. }
  268. function CGEventCreateSourceFromEvent( event: CGEventRef ): CGEventSourceRef; external name '_CGEventCreateSourceFromEvent';
  269. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  270. { Set the event source of an event. }
  271. procedure CGEventSetSource( event: CGEventRef; source: CGEventSourceRef ); external name '_CGEventSetSource';
  272. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  273. { Return the event type of an event (left mouse down, for example). }
  274. function CGEventGetType( event: CGEventRef ): CGEventType; external name '_CGEventGetType';
  275. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  276. { Set the event type of an event. }
  277. procedure CGEventSetType( event: CGEventRef; typ: CGEventType ); external name '_CGEventSetType';
  278. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  279. { Return the timestamp of an event. }
  280. function CGEventGetTimestamp( event: CGEventRef ): CGEventTimestamp; external name '_CGEventGetTimestamp';
  281. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  282. { Set the timestamp of an event. }
  283. procedure CGEventSetTimestamp( event: CGEventRef; timestamp: CGEventTimestamp ); external name '_CGEventSetTimestamp';
  284. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  285. { Return the location of an event in global display coordinates. }
  286. function CGEventGetLocation( event: CGEventRef ): CGPoint; external name '_CGEventGetLocation';
  287. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  288. { Return the location of an event relative to the lower-left corner of the
  289. main display. }
  290. function CGEventGetUnflippedLocation( event: CGEventRef ): CGPoint; external name '_CGEventGetUnflippedLocation';
  291. (* CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA) *)
  292. { Set the location of an event in global display coordinates. }
  293. procedure CGEventSetLocation( event: CGEventRef; location: CGPoint ); external name '_CGEventSetLocation';
  294. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  295. { Return the event flags of an event. }
  296. function CGEventGetFlags( event: CGEventRef ): CGEventFlags; external name '_CGEventGetFlags';
  297. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  298. { Set the event flags of an event. }
  299. procedure CGEventSetFlags( event: CGEventRef; flags: CGEventFlags ); external name '_CGEventSetFlags';
  300. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  301. { Return the Unicode string associated with a keyboard event.
  302. When you call this function with a NULL string or a maximum string length
  303. of 0, the function still returns the actual count of Unicode characters
  304. in the event. }
  305. procedure CGEventKeyboardGetUnicodeString( event: CGEventRef; maxStringLength: UniCharCount; var actualStringLength: UniCharCount; unicodeString: {variable-size-array} UniCharPtr ); external name '_CGEventKeyboardGetUnicodeString';
  306. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  307. { Set the Unicode string associated with a keyboard event.
  308. By default, the system translates the virtual key code in a keyboard
  309. event into a Unicode string based on the keyboard ID in the event source.
  310. This function allows you to manually override this string. Note that
  311. application frameworks may ignore the Unicode string in a keyboard event
  312. and do their own translation based on the virtual keycode and perceived
  313. event state. }
  314. procedure CGEventKeyboardSetUnicodeString( event: CGEventRef; stringLength: UniCharCount; {const} unicodeString: {variable-size-array} UniCharPtr ); external name '_CGEventKeyboardSetUnicodeString';
  315. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  316. { Return the integer value of a field in an event. }
  317. function CGEventGetIntegerValueField( event: CGEventRef; field: CGEventField ): SInt64; external name '_CGEventGetIntegerValueField';
  318. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  319. { Set the integer value of a field in an event.
  320. Before calling this function, the event type must be set using a typed
  321. event creation function such as `CGEventCreateMouseEvent', or by calling
  322. `CGEventSetType'.
  323. If you are creating a mouse event generated by a tablet, call this
  324. function and specify the field `kCGMouseEventSubtype' with a value of
  325. `kCGEventMouseSubtypeTabletPoint' or `kCGEventMouseSubtypeTabletProximity'
  326. before setting other parameters. }
  327. procedure CGEventSetIntegerValueField( event: CGEventRef; field: CGEventField; value: SInt64 ); external name '_CGEventSetIntegerValueField';
  328. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  329. { Return the floating-point value of a field in an event.
  330. In cases where the field value is represented within the event by a fixed
  331. point number or an integer, the result is scaled to the appropriate range
  332. as part of creating the floating-point representation. }
  333. function CGEventGetDoubleValueField( event: CGEventRef; field: CGEventField ): Float64; external name '_CGEventGetDoubleValueField';
  334. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  335. { Set the floating-point value of a field in an event.
  336. Before calling this function, the event type must be set using a typed
  337. event creation function such as `CGEventCreateMouseEvent', or by calling
  338. `CGEventSetType'.
  339. In cases where the field’s value is represented within the event by a
  340. fixed point number or integer, the value parameter is scaled as needed
  341. and converted to the appropriate type. }
  342. procedure CGEventSetDoubleValueField( event: CGEventRef; field: CGEventField; value: Float64 ); external name '_CGEventSetDoubleValueField';
  343. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  344. { Event taps.
  345. A function registers an event tap, taking a pointer to the program's tap
  346. function and an arbitrary reference to be passed to the tap function, and
  347. returning a `CFMachPortRef' the program can add to the appropriate run
  348. loop by creating a surce and using `CFRunLoopAddSource'.
  349. Taps may be placed at the point where HIDSystem events enter the server,
  350. at the point where HIDSystem and remote control events enter a session,
  351. at the point where events have been annotated to flow to a specific
  352. application, or at the point where events are delivered to the
  353. application. Taps may be inserted at a specified point at the head of
  354. pre-existing filters, or appended after any pre-existing filters.
  355. Taps may be passive event listeners, or active filters. An active filter
  356. may pass an event through unmodified, modify an event, or discard an
  357. event. When a tap is registered, it identifies the set of events to be
  358. observed with a mask, and indicates if it is a passive or active event
  359. filter. Multiple event type bitmasks may be ORed together.
  360. Taps may only be placed at `kCGHIDEventTap' by a process running as the
  361. root user. NULL is returned for other users.
  362. Taps placed at `kCGHIDEventTap', `kCGSessionEventTap',
  363. `kCGAnnotatedSessionEventTap', or on a specific process may only receive
  364. key up and down events if access for assistive devices is enabled
  365. (Preferences Accessibility panel, Keyboard view) or the caller is enabled
  366. for assistive device access, as by `AXMakeProcessTrusted'. If the tap is
  367. not permitted to monitor these events when the tap is created, then the
  368. appropriate bits in the mask are cleared. If that results in an empty
  369. mask, then NULL is returned.
  370. An event tap is represented as a `CFMachPortRef'. The event tap may be
  371. added to an appropriate run loop by calling `CFRunLoopAddSource'.
  372. Releasing the CFMachPortRef will release the tap.
  373. A `CGEventTapProxy' is an opaque reference to state within the client
  374. application associated with the tap. The tap function may pass this
  375. reference to other functions, such as the event-posting routines.
  376. The event tap callback runs from the CFRunLoop to which the tap
  377. CFMachPort is added as a source. Thread safety is defined by the
  378. CFRunLoop and its environment. }
  379. { Create an event tap. }
  380. function CGEventTapCreate( tap: CGEventTapLocation; place: CGEventTapPlacement; options: CGEventTapOptions; eventsOfInterest: CGEventMask; callback: CGEventTapCallBack; userInfo: UnivPtr ): CFMachPortRef; external name '_CGEventTapCreate';
  381. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  382. { Create an event tap for a specified process.
  383. Events routed to individual applications may be tapped using another
  384. function. `CGEventTapCreateForPSN' will report all events routed to the
  385. specified application. }
  386. function CGEventTapCreateForPSN( processSerialNumber: UnivPtr; place: CGEventTapPlacement; options: CGEventTapOptions; eventsOfInterest: CGEventMask; callback: CGEventTapCallBack; userInfo: UnivPtr ): CFMachPortRef; external name '_CGEventTapCreateForPSN';
  387. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  388. { Enable or disable an event tap.
  389. Taps are normally enabled when created. If a tap becomes unresponsive or
  390. a user requests taps be disabled, an appropriate `kCGEventTapDisabled...'
  391. event is passed to the registered CGEventTapCallBack function. An event
  392. tap may be re-enabled by calling this function. }
  393. procedure CGEventTapEnable( tap: CFMachPortRef; enable: CBool ); external name '_CGEventTapEnable';
  394. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  395. { Return true if `tap' is enabled; false otherwise. }
  396. function CGEventTapIsEnabled( tap: CFMachPortRef ): CBool; external name '_CGEventTapIsEnabled';
  397. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  398. { Post an event from an event tap into the event stream.
  399. You can use this function to post a new event at the same point to which
  400. an event returned from an event tap callback function would be posted.
  401. The new event enters the system before the event returned by the callback
  402. enters the system. Events posted into the system will be seen by all taps
  403. placed after the tap posting the event. }
  404. procedure CGEventTapPostEvent( proxy: CGEventTapProxy; event: CGEventRef ); external name '_CGEventTapPostEvent';
  405. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  406. { Post an event into the event stream at a specified location.
  407. This function posts the specified event immediately before any event taps
  408. instantiated for that location, and the event passes through any such
  409. taps. }
  410. procedure CGEventPost( tap: CGEventTapLocation; event: CGEventRef ); external name '_CGEventPost';
  411. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  412. { Post an event into the event stream for a specific application.
  413. This function makes it possible for an application to establish
  414. an event routing policy, for example, by tapping events at the
  415. `kCGAnnotatedSessionEventTap' location and then posting the events
  416. to another desired process.
  417. This function posts the specified event immediately before any event taps
  418. instantiated for the specified process, and the event passes through any
  419. such taps. }
  420. procedure CGEventPostToPSN( processSerialNumber: UnivPtr; event: CGEventRef ); external name '_CGEventPostToPSN';
  421. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  422. { Gets a list of currently installed event taps.
  423. `tapList' is an array of event tap information structures of length
  424. `maxNumberOfTaps'. You are responsible for allocating storage for this
  425. array. On return, your array contains a list of currently installed event
  426. taps. On return, the number of event taps that are currently installed is
  427. stored in `eventTapCount'. If you pass NULL in this parameter, the
  428. `maxNumberOfTaps' parameter is ignored, and the number of event taps that
  429. are currently installed is stored in `eventTapCount'.
  430. Each call to this function has the side effect of resetting the minimum
  431. and maximum latencies in the `tapList' parameter to the corresponding
  432. average values. Values reported in these fields reflect the minimum and
  433. maximum values seen since the preceding call, or the instantiation of the
  434. tap. This allows a monitoring tool to evaluate the best and worst case
  435. latency over time and under various operating conditions. }
  436. function CGGetEventTapList( maxNumberOfTaps: UInt32; tapList: {variable-size-array} CGEventTapInformationPtr; var eventTapCount: UInt32 ): CGError; external name '_CGGetEventTapList';
  437. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_NA) *)
  438. {$endc}
  439. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  440. end.
  441. {$endc} {not MACOSALLINCLUDE}