KeyEvents.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. {$mode macpas}
  2. {$packenum 1}
  3. {$macro on}
  4. {$inline on}
  5. {$calling mwpascal}
  6. unit KeyEvents;
  7. interface
  8. {$linkframework Carbon}
  9. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  10. {$setc GAP_INTERFACES_VERSION := $0305}
  11. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  12. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  13. {$endc}
  14. {$ifc defined CPUPOWERPC and defined CPUI386}
  15. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  16. {$endc}
  17. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  18. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  19. {$endc}
  20. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  21. {$setc __ppc__ := 1}
  22. {$elsec}
  23. {$setc __ppc__ := 0}
  24. {$endc}
  25. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  26. {$setc __ppc64__ := 1}
  27. {$elsec}
  28. {$setc __ppc64__ := 0}
  29. {$endc}
  30. {$ifc not defined __i386__ and defined CPUI386}
  31. {$setc __i386__ := 1}
  32. {$elsec}
  33. {$setc __i386__ := 0}
  34. {$endc}
  35. {$ifc not defined __x86_64__ and defined CPUX86_64}
  36. {$setc __x86_64__ := 1}
  37. {$elsec}
  38. {$setc __x86_64__ := 0}
  39. {$endc}
  40. {$ifc not defined __arm__ and defined CPUARM}
  41. {$setc __arm__ := 1}
  42. {$elsec}
  43. {$setc __arm__ := 0}
  44. {$endc}
  45. {$ifc defined cpu64}
  46. {$setc __LP64__ := 1}
  47. {$elsec}
  48. {$setc __LP64__ := 0}
  49. {$endc}
  50. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  51. {$error Conflicting definitions for __ppc__ and __i386__}
  52. {$endc}
  53. {$ifc defined __ppc__ and __ppc__}
  54. {$setc TARGET_CPU_PPC := TRUE}
  55. {$setc TARGET_CPU_PPC64 := FALSE}
  56. {$setc TARGET_CPU_X86 := FALSE}
  57. {$setc TARGET_CPU_X86_64 := FALSE}
  58. {$setc TARGET_CPU_ARM := FALSE}
  59. {$setc TARGET_OS_MAC := TRUE}
  60. {$setc TARGET_OS_IPHONE := FALSE}
  61. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  62. {$elifc defined __ppc64__ and __ppc64__}
  63. {$setc TARGET_CPU_PPC := FALSE}
  64. {$setc TARGET_CPU_PPC64 := TRUE}
  65. {$setc TARGET_CPU_X86 := FALSE}
  66. {$setc TARGET_CPU_X86_64 := FALSE}
  67. {$setc TARGET_CPU_ARM := FALSE}
  68. {$setc TARGET_OS_MAC := TRUE}
  69. {$setc TARGET_OS_IPHONE := FALSE}
  70. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  71. {$elifc defined __i386__ and __i386__}
  72. {$setc TARGET_CPU_PPC := FALSE}
  73. {$setc TARGET_CPU_PPC64 := FALSE}
  74. {$setc TARGET_CPU_X86 := TRUE}
  75. {$setc TARGET_CPU_X86_64 := FALSE}
  76. {$setc TARGET_CPU_ARM := FALSE}
  77. {$ifc defined(iphonesim)}
  78. {$setc TARGET_OS_MAC := FALSE}
  79. {$setc TARGET_OS_IPHONE := TRUE}
  80. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  81. {$elsec}
  82. {$setc TARGET_OS_MAC := TRUE}
  83. {$setc TARGET_OS_IPHONE := FALSE}
  84. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  85. {$endc}
  86. {$elifc defined __x86_64__ and __x86_64__}
  87. {$setc TARGET_CPU_PPC := FALSE}
  88. {$setc TARGET_CPU_PPC64 := FALSE}
  89. {$setc TARGET_CPU_X86 := FALSE}
  90. {$setc TARGET_CPU_X86_64 := TRUE}
  91. {$setc TARGET_CPU_ARM := FALSE}
  92. {$setc TARGET_OS_MAC := TRUE}
  93. {$setc TARGET_OS_IPHONE := FALSE}
  94. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  95. {$elifc defined __arm__ and __arm__}
  96. {$setc TARGET_CPU_PPC := FALSE}
  97. {$setc TARGET_CPU_PPC64 := FALSE}
  98. {$setc TARGET_CPU_X86 := FALSE}
  99. {$setc TARGET_CPU_X86_64 := FALSE}
  100. {$setc TARGET_CPU_ARM := TRUE}
  101. { will require compiler define when/if other Apple devices with ARM cpus ship }
  102. {$setc TARGET_OS_MAC := FALSE}
  103. {$setc TARGET_OS_IPHONE := TRUE}
  104. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  105. {$elsec}
  106. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  107. {$endc}
  108. {$ifc defined __LP64__ and __LP64__ }
  109. {$setc TARGET_CPU_64 := TRUE}
  110. {$elsec}
  111. {$setc TARGET_CPU_64 := FALSE}
  112. {$endc}
  113. {$ifc defined FPC_BIG_ENDIAN}
  114. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  115. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  116. {$elifc defined FPC_LITTLE_ENDIAN}
  117. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  118. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  119. {$elsec}
  120. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  121. {$endc}
  122. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  123. {$setc CALL_NOT_IN_CARBON := FALSE}
  124. {$setc OLDROUTINENAMES := FALSE}
  125. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  126. {$setc OPAQUE_UPP_TYPES := TRUE}
  127. {$setc OTCARBONAPPLICATION := TRUE}
  128. {$setc OTKERNEL := FALSE}
  129. {$setc PM_USE_SESSION_APIS := TRUE}
  130. {$setc TARGET_API_MAC_CARBON := TRUE}
  131. {$setc TARGET_API_MAC_OS8 := FALSE}
  132. {$setc TARGET_API_MAC_OSX := TRUE}
  133. {$setc TARGET_CARBON := TRUE}
  134. {$setc TARGET_CPU_68K := FALSE}
  135. {$setc TARGET_CPU_MIPS := FALSE}
  136. {$setc TARGET_CPU_SPARC := FALSE}
  137. {$setc TARGET_OS_UNIX := FALSE}
  138. {$setc TARGET_OS_WIN32 := FALSE}
  139. {$setc TARGET_RT_MAC_68881 := FALSE}
  140. {$setc TARGET_RT_MAC_CFM := FALSE}
  141. {$setc TARGET_RT_MAC_MACHO := TRUE}
  142. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  143. {$setc TYPE_BOOL := FALSE}
  144. {$setc TYPE_EXTENDED := FALSE}
  145. {$setc TYPE_LONGLONG := TRUE}
  146. {$ifc TARGET_OS_MAC and TARGET_CPU_64}
  147. {
  148. QuickTime 3.0 supports GetKeys() on unix and win32
  149. }
  150. type
  151. KeyMap = packed array [0..127] of boolean;
  152. {
  153. * GetKeys()
  154. *
  155. * Mac OS X threading:
  156. * Not thread safe
  157. *
  158. * Availability:
  159. * Mac OS X: in version 10.0 and later in Carbon.framework
  160. * CarbonLib: in CarbonLib 1.0 and later
  161. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  162. }
  163. procedure __GetKeys( var theKeys: KeyMap ); external name '_GetKeys';
  164. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER *)
  165. {
  166. With GPC and FPC on PowerPC, the bytes of the KeyMap must be swapped
  167. }
  168. procedure GetKeys( var theKeys: KeyMap );
  169. {$endc} {TARGET_OS_MAC and TARGET_CPU_64}
  170. implementation
  171. {$ifc TARGET_OS_MAC and TARGET_CPU_64}
  172. {$ifc TARGET_RT_BIG_ENDIAN}
  173. procedure GetKeys( var theKeys: KeyMap );
  174. var
  175. theReverseKeys: KeyMap;
  176. theKey: 0..127;
  177. begin
  178. __GetKeys( theReverseKeys);
  179. for theKey:= 0 to 127 do
  180. theKeys[ theKey]:= theReverseKeys[ ((theKey div 8) * 8) + (7 - (theKey mod 8))]
  181. end;
  182. {$elsec}
  183. procedure GetKeys( var theKeys: KeyMap );
  184. begin
  185. __GetKeys( theKeys)
  186. end;
  187. {$endc}
  188. {$endc} {TARGET_OS_MAC and TARGET_CPU_64}
  189. end.