keybd.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2008 Free Pascal development team.
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. ********************************************************************** }
  10. //
  11. // Module: keybd.h
  12. //
  13. // Non Win32 defines and structs for WinCE keyboard.
  14. //
  15. //
  16. // Microsoft Windows Mobile 6.0 for PocketPC SDK.
  17. //
  18. unit keybd;
  19. interface
  20. uses windows, WinIOCtl;
  21. // EXTERNAL DRIVERS
  22. // KEY_STATE_FLAGS | Flags for keyboard events and shift state.
  23. {
  24. These flags perform a number of functions:
  25. The low order bits are used to keep track of a key state. This
  26. allows using 256 UINT8's for the key state array just like Windows does
  27. already.
  28. The upper bits keep track of shift state on a per key basis. Since
  29. we are not maintaining a complete key state array for each task, this
  30. gives us some extra info without a big memory penalty.
  31. The KeyStateDownFlag does double duty internal to the driver to
  32. identify key up or key down events.
  33. KeyShiftDeadFlag is set by the <f KeybdDriverVKeyToUnicode> function
  34. to signify that the character generated is a dead character.
  35. KeyShiftNoCharacterFlag is set by the <f KeybdDriverVKeyToUnicode>
  36. function to signify that there is no valid character to generate for the
  37. given virtual key event. This may be the case on a key up event or a key
  38. which only changes the shift state.
  39. The control, alt, shift and capital flags are set by the <f
  40. KeybdDriverVKeyToUnicode> function to encapsulate the shift state when the
  41. character was generated.
  42. KeybdDriverVKeyToUnicode
  43. KeybdEventCallback
  44. }
  45. type
  46. KEY_STATE_FLAGS = UINT32;
  47. const
  48. KeyStateToggledFlag = $0001; // Key is toggled.
  49. KeyStateGetAsyncDownFlag = $0002; // Key went down since last GetAsyncKey call.
  50. KeyStateReserved4 = $0004;
  51. KeyStateReserved8 = $0008;
  52. KeyStateReserved10 = $0010;
  53. KeyStateReserved20 = $0020;
  54. KeyStatePrevDownFlag = $0040; // Key was previously down.
  55. KeyStateDownFlag = $0080; // Key is currently down.
  56. KeyStateKeyEventFlag = $80000000; // Internal
  57. KeyShiftAnyCtrlFlag = $40000000; // L or R control is down.
  58. KeyShiftAnyShiftFlag = $20000000; // L or R shift is down.
  59. KeyShiftAnyAltFlag = $10000000; // L or R alt is down.
  60. KeyShiftCapitalFlag = $08000000; // VK_CAPITAL is toggled.
  61. KeyShiftLeftCtrlFlag = $04000000; // L control is down.
  62. KeyShiftLeftShiftFlag = $02000000; // L shift is down.
  63. KeyShiftLeftAltFlag = $01000000; // L alt is down.
  64. KeyShiftLeftWinFlag = $00800000; // L Win key is down.
  65. KeyShiftRightCtrlFlag = $00400000; // R control is down.
  66. KeyShiftRightShiftFlag = $00200000; // R shift is down.
  67. KeyShiftRightAltFlag = $00100000; // R alt is down.
  68. KeyShiftRightWinFlag = $00080000; // R Win key is down.
  69. KeyShiftReserved40000 = $00040000; // Reserved.
  70. KeyShiftDeadFlag = $00020000; // Corresponding char is dead char.
  71. KeyShiftNoCharacterFlag = $00010000; // No corresponding char.
  72. KeyShiftLanguageFlag1 = $00008000; // Use for language specific shifts.
  73. KeyShiftKeybdEventFlag = $00004000; // Not for external use.
  74. KeyShiftUseVKNullFlag = $00002000; // Not for external use.
  75. KeyShiftNumLockFlag = $00001000; // NumLock toggled state.
  76. KeyShiftScrollLockFlag = $00000800; // ScrollLock toggled state.
  77. KeyShiftReserved400 = $00000400; // Reserved.
  78. KeyShiftReserved200 = $00000200; // Reserved.
  79. KeyShiftReserved100 = $00000100; // Reserved.
  80. // Japanese keyboard
  81. KeyShiftKanaFlag = KeyShiftLanguageFlag1; // Kana lock is toggled.
  82. function KeyStateIsDown(Flags:KEY_STATE_FLAGS):BOOL;
  83. function KeyStateIsPrevDown(Flags:KEY_STATE_FLAGS):BOOL;
  84. function KeyStateIsToggled(Flags:KEY_STATE_FLAGS):BOOL;
  85. function KeyStateIsDownTransition(Flags:KEY_STATE_FLAGS):BOOL;
  86. const
  87. COUNT_VKEYS = 256;
  88. {
  89. EXTERNAL DRIVERS
  90. KEY_STATE | Array of virtual key states.
  91. }
  92. type
  93. KEY_STATE = array[0..COUNT_VKEYS-1] of UINT8;
  94. //
  95. // KeyboardDriverGetDeviceInfo query capability definitions
  96. //
  97. // EXTERNAL DRIVERS
  98. // ULONG | KBDI_VKEY_TO_UNICODE_INFO_ID |
  99. // Id for KeybdDriverGetInfo to get Unicode conversion info.
  100. //
  101. // xref
  102. // KeybdDriverGetInfo
  103. // KBDI_VKEY_TO_UNICODE_INFO
  104. // KeybdDriverVKeyToUnicode
  105. const
  106. KBDI_VKEY_TO_UNICODE_INFO_ID = 0;
  107. // EXTERNAL DRIVERS KEYBD_DRIVER
  108. // KBDI_VKEY_TO_UNICODE_INFO
  109. // Info required to set up for Unicode conversion.
  110. //
  111. // xref
  112. // KeybdDriverGetInfo
  113. // KBDI_VKEY_TO_UNICODE_INFO_ID
  114. // KeybdDriverVKeyToUnicode
  115. // TO_UNICODE_STATE
  116. {
  117. cbToUnicodeState is the number of bytes necessary to store the
  118. driver specific state which is required to generate characters from a
  119. virtual key. For example, a French keyboard driver may need to remember
  120. that an accent key was previously pressed in order to decide on a specific
  121. Unicode character to generate for a virtual key. This value may be 0 if
  122. no other state besides <t KEY_STATE> is required to generate characters,
  123. e.g., English keyboard drivers.
  124. cMaxToUnicodeCharacters is the maximum number of characters that may
  125. be generated by a call to KeybdDriverVKeyToUnicode. For example, if a
  126. user presses the '^' key and then the 'b' key, a French keyboard driver
  127. would generate the two characters, '^' 'b', when the second key is
  128. pressed. Note that this is not the count of bytes required to store the
  129. characters, it is just the number of characters.
  130. }
  131. type
  132. KBDI_VKEY_TO_UNICODE_INFO = record
  133. cbToUnicodeState:UINT32; // @FIELD Count of bytes required
  134. // for state info for Unicode
  135. // character generation.
  136. cMaxToUnicodeCharacters:UINT32; // @FIELD Maximum number of characters
  137. // generated for a single virtual key.
  138. end;
  139. // EXTERNAL DRIVERS
  140. // ULONG | KBDI_AUTOREPEAT_INFO_ID
  141. // Id for KeybdDriverGetInfo to get keyboard auto-repeat info.
  142. //
  143. // xref
  144. // KeybdDriverGetInfo
  145. // KBDI_AUTOREPEAT_INFO
  146. // KBDI_AUTOREPEAT_SELECTIONS_INFO_ID
  147. const
  148. KBDI_AUTOREPEAT_INFO_ID = 1;
  149. // Info about the keyboard autorepeat capabilities and settings.
  150. {
  151. cInitialDelaysSelectable gives the number of initial delays which
  152. may be set. Query again using <c KBDI_AUTOREPEAT_SELECTIONS_INFO_ID> to
  153. get the actual values available.
  154. cRepeatRatesSelectable is similar to cInitialDelaysSelectable except
  155. that it gives the number of repeat rates available.
  156. }
  157. type
  158. KBDI_AUTOREPEAT_INFO = record
  159. CurrentInitialDelay:INT32; // @FIELD Current initial delay in milliseconds.
  160. CurrentRepeatRate:INT32; // @FIELD Current repeat rate in keys per second.
  161. cInitialDelaysSelectable:INT32; // @FIELD Number of initial delays selectable.
  162. cRepeatRatesSelectable:INT32; // @FIELD Number of repeat rates supported.
  163. end;
  164. const
  165. KBD_AUTO_REPEAT_INITIAL_DELAY_DEFAULT = 500;
  166. KBD_AUTO_REPEAT_INITIAL_DELAY_MIN = 250;
  167. KBD_AUTO_REPEAT_INITIAL_DELAY_MAX = 1000;
  168. KBD_AUTO_REPEAT_KEYS_PER_SEC_DEFAULT = 20;
  169. KBD_AUTO_REPEAT_KEYS_PER_SEC_MIN = 2;
  170. KBD_AUTO_REPEAT_KEYS_PER_SEC_MAX = 30;
  171. // Id for KeybdDriverGetInfo to get keyboard auto-repeat selections info.
  172. {
  173. When KeybdDriverGetInfo is called with this value, the lpOutput
  174. parameter should be a pointer to an array of INT32's to hold the selection
  175. info. The initial delays will be put at the beginning of the array
  176. followed by the repeat rate selections. The number of initial delay
  177. values is determined by calling <f KeybdDriverGetInfo> using <c
  178. KBDI_AUTOREPEAT_INFO_ID> and looking at the returned
  179. cInitialDelaysSelectable field. If this value is -1, there will be two
  180. (2) values, the min and max and the initial delay may be set to any value
  181. in this range. This value may be 0 if the initial delay is not settable.
  182. Similarly, if cRepeatRatesSelectable is 0, there will be no repeat rate
  183. information. If it is -1, there will be two (2) values, the min and max.
  184. Initial delay values are in milliseconds. Repeat rates are in keys per
  185. second.
  186. }
  187. const
  188. KBDI_AUTOREPEAT_SELECTIONS_INFO_ID = 2;
  189. // INTERNATIONAL
  190. const
  191. KBDI_KEYBOARD_STATUS_ID = 3;
  192. const
  193. KBDI_KEYBOARD_PRESENT = $0001;
  194. KBDI_KEYBOARD_ENABLED = $0002;
  195. KBDI_KEYBOARD_ENTER_ESC = $0004;
  196. KBDI_KEYBOARD_ALPHA_NUM = $0008;
  197. // Reserve for SHIME_MODE.
  198. // Pass in the SHIME_MODE as the input parameter.
  199. const
  200. KBDI_SHIME_MODE_ID = 4;
  201. KBDI_SHIME_MODE_NONE = $0000;
  202. KBDI_SHIME_MODE_SPELL = $0001;
  203. KBDI_SHIME_MODE_SPELL_CAPS = $0002;
  204. KBDI_SHIME_MODE_SPELL_CAPS_LOCK = $0003;
  205. KBDI_SHIME_MODE_AMBIGUOUS = $0004;
  206. KBDI_SHIME_MODE_AMBIGUOUS_CAPS = $0005;
  207. KBDI_SHIME_MODE_AMBIGUOUS_CAPS_LOCK = $0006;
  208. KBDI_SHIME_MODE_NUMBERS = $0007;
  209. KBDI_SHIME_MODE_CUSTOM = $0008;
  210. // External keyboard interface
  211. const
  212. DEVCLASS_KEYBOARD_STRING = '{CBE6DDF2-F5D4-4E16-9F61-4CCC0B6695F3}';
  213. DEVCLASS_KEYBOARD_GUID:System.TGUID = (D1: $CBE6DDF2; D2: $F5D4; D3: $4E16; D4: ($9F, $61, $4C, $CC, $0B, $66, $95, $F3));
  214. // DEVCLASS_KEYBOARD_GUID:System.TGUID = '{CBE6DDF2-F5D4-4E16-9F61-4CCC0B6695F3}';
  215. // Pass in the KEY_STATE_FLAGS as the input parameter.
  216. const
  217. IOCTL_KBD_SET_MODIFIERS = (FILE_DEVICE_KEYBOARD shl 16) or
  218. (1 shl 2) or
  219. METHOD_BUFFERED or
  220. (FILE_ANY_ACCESS shl 14);
  221. IOCTL_HID_SET_MODIFIERS = IOCTL_KBD_SET_MODIFIERS;
  222. // Pass in the KBDI_AUTOREPEAT_INFO as the input parameter.
  223. const
  224. IOCTL_KBD_SET_AUTOREPEAT = (FILE_DEVICE_KEYBOARD shl 16) or
  225. (2 shl 2) or
  226. METHOD_BUFFERED or
  227. (FILE_ANY_ACCESS shl 14);
  228. IOCTL_HID_SET_AUTOREPEAT = IOCTL_KBD_SET_AUTOREPEAT;
  229. // Pass in the Input Language's fLocaleFlags as the input parameter.
  230. const
  231. IOCTL_KBD_SET_LOCALE_FLAGS = (FILE_DEVICE_KEYBOARD shl 16) or
  232. (3 shl 2) or
  233. METHOD_BUFFERED or
  234. (FILE_ANY_ACCESS shl 14);
  235. implementation
  236. function KeyStateIsDown(Flags:KEY_STATE_FLAGS):BOOL; inline;
  237. begin
  238. KeyStateIsDown:=(Flags and KeyStateDownFlag)<>0;
  239. end;
  240. function KeyStateIsPrevDown(Flags:KEY_STATE_FLAGS):BOOL; inline;
  241. begin
  242. KeyStateIsPrevDown:=(Flags and KeyStatePrevDownFlag)<>0;
  243. end;
  244. function KeyStateIsToggled(Flags:KEY_STATE_FLAGS):BOOL; inline;
  245. begin
  246. KeyStateIsToggled:=(Flags and KeyStateToggledFlag)<>0;
  247. end;
  248. function KeyStateIsDownTransition(Flags:KEY_STATE_FLAGS):BOOL; inline;
  249. begin
  250. KeyStateIsDownTransition:=KeyStateIsDown(Flags) and (not KeyStateIsPrevDown(Flags));
  251. end;
  252. end.