kbdcalls.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. {Set tabsize to 4.}
  2. {****************************************************************************
  3. KBDCALLS interface unit
  4. FPK-Pascal Runtime Library for OS/2
  5. Copyright (c) 1993,94 by Florian Kl„mpfl
  6. Copyright (c) 1997 by Dani‰l Mantione
  7. Copyright (c) 1998 by Tomas Hajny
  8. The FPK-Pascal runtime library is distributed under the Library GNU Public
  9. License v2. So is this unit. The Library GNU Public License requires you to
  10. distribute the source code of this unit with any product that uses it.
  11. Because the EMX library isn't under the LGPL, we grant you an exception to
  12. this, and that is, when you compile a program with the FPK Pascal compiler,
  13. you do not need to ship source code with that program, AS LONG AS YOU ARE
  14. USING UNMODIFIED CODE! If you modify this code, you MUST change the next
  15. line:
  16. <This is an official, unmodified FPK Pascal source code file.>
  17. Send us your modified files, we can work together if you want!
  18. FPK-Pascal is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. Library GNU General Public License for more details.
  22. You should have received a copy of the Library GNU General Public License
  23. along with FPK-Pascal; see the file COPYING.LIB. If not, write to
  24. the Free Software Foundation, 59 Temple Place - Suite 330,
  25. Boston, MA 02111-1307, USA.
  26. ****************************************************************************}
  27. unit KbdCalls;
  28. { Interface library to KBDCALLS.DLL (through EMXWRAP.DLL)
  29. Changelog:
  30. People:
  31. TH - Tomas Hajny
  32. Date: Description of change: Changed by:
  33. - First released version 0.99 TH
  34. Coding style:
  35. I have tried to use the same coding style as Dani‰l Mantione in unit
  36. DOSCALLS, although I can't say I would write it the same way otherwise (I
  37. would write much more spaces myself, at least). Try to use it as well,
  38. please. Original note by Dani‰l Mantione follows:
  39. It may be well possible that coding style feels a bit strange to you.
  40. Nevertheless I friendly ask you to try to make your changes not look all
  41. to different. To make life easier, set your IDE to use tab characters,
  42. turn optimal fill, autoindent and backspace unindents on and set a
  43. tabsize of 4.}
  44. {***************************************************************************}
  45. interface
  46. {***************************************************************************}
  47. uses strings;
  48. {$ifdef FPK}
  49. {$packrecords 1}
  50. {$endif FPK}
  51. const
  52. {FnMask}
  53. KR_KBDCHARIN =$00000001;
  54. KR_KBDPEEK =$00000002;
  55. KR_KBDFLUSHBUFFER =$00000004;
  56. KR_KBDGETSTATUS =$00000008;
  57. KR_KBDSETSTATUS =$00000010;
  58. KR_KBDSTRINGIN =$00000020;
  59. KR_KBDOPEN =$00000040;
  60. KR_KBDCLOSE =$00000080;
  61. KR_KBDGETFOCUS =$00000100;
  62. KR_KBDFREEFOCUS =$00000200;
  63. KR_KBDGETCP =$00000400;
  64. KR_KBDSETCP =$00000800;
  65. KR_KBDXLATE =$00001000;
  66. KR_KBDSETCUSTXT =$00002000;
  67. {WaitFlag}
  68. IO_WAIT =0;
  69. {KbdCharIn: wait for a character if one is not available}
  70. {KbdGetFocus: wait for the focus}
  71. IO_NOWAIT =1;
  72. {KbdCharIn: immediate return if no character is available}
  73. {KbdGetFocus: do not wait for the focus}
  74. {TKbdInfo.fsMask}
  75. KEYBOARD_ECHO_ON =$0001;
  76. KEYBOARD_ECHO_OFF =$0002;
  77. KEYBOARD_BINARY_MODE =$0004;
  78. KEYBOARD_ASCII_MODE =$0008;
  79. KEYBOARD_MODIFY_STATE =$0010;
  80. KEYBOARD_MODIFY_INTERIM =$0020;
  81. KEYBOARD_MODIFY_TURNAROUND =$0040;
  82. KEYBOARD_2B_TURNAROUND =$0080;
  83. KEYBOARD_SHIFT_REPORT =$0100;
  84. {TKbdInfo.fsState/TKbdKeyInfo.fsState/TKbdTrans.fsState}
  85. KBDSTF_RIGHTSHIFT =$0001;
  86. KBDSTF_LEFTSHIFT =$0002;
  87. KBDSTF_CONTROL =$0004;
  88. KBDSTF_ALT =$0008;
  89. KBDSTF_SCROLLLOCK_ON =$0010;
  90. KBDSTF_NUMLOCK_ON =$0020;
  91. KBDSTF_CAPSLOCK_ON =$0040;
  92. KBDSTF_INSERT_ON =$0080;
  93. KBDSTF_LEFTCONTROL =$0100;
  94. KBDSTF_LEFTALT =$0200;
  95. KBDSTF_RIGHTCONTROL =$0400;
  96. KBDSTF_RIGHTALT =$0800;
  97. KBDSTF_SCROLLLOCK =$1000;
  98. KBDSTF_NUMLOCK =$2000;
  99. KBDSTF_CAPSLOCK =$4000;
  100. KBDSTF_SYSREQ =$8000;
  101. {TKbdTrans.fbStatus}
  102. KBDTRF_SHIFT_KEY_IN =$01; {shift status returned}
  103. {without character }
  104. KBDTRF_EXTENDED_KEY_IN =$02; {extended key code }
  105. {from the keyboard,}
  106. {not a character }
  107. KBDTRF_CONVERSION_REQUEST =$20; {immediate conversion}
  108. {requested }
  109. KBDTRF_FINAL_CHAR_IN =$40; {either $40 or $80 or both}
  110. KBDTRF_INTERIM_CHAR_IN =$80; {must be present }
  111. type
  112. {TKbdKeyInfo - character data structure for KbdCharIn and KbdPeek}
  113. (* #pragma pack(2) ??? *)
  114. TKbdKeyInfo=record
  115. chChar:char; {ASCII character code; the scan code received}
  116. {from the keyboard is translated to the ASCII}
  117. {character code }
  118. chScan:byte; {scan Code received from the keyboard}
  119. fbStatus:byte; {state of the keystroke event, see KBDTRF_*}
  120. bNlsShift:byte; {NLS shift status (always 0?)}
  121. fsState:word; {shift key status, see KBDSTF_*}
  122. time:longint; {time stamp indicating when a key was pressed,}
  123. {specified in milliseconds from the time }
  124. {the system was started }
  125. end;
  126. PKbdKeyInfo=^TKbdKeyInfo;
  127. {structure for KbdStringIn}
  128. TStringInBuf=record
  129. cb:word;
  130. cchIn:word;
  131. end;
  132. PStringInBuf=TStringInBuf;
  133. {TKbdInfo structure, for KbdSet/GetStatus}
  134. TKbdInfo=record
  135. cb,
  136. fsMask,
  137. chTurnAround,
  138. fsInterim,
  139. fsState:word;
  140. end;
  141. PKbdInfo=^TKbdInfo;
  142. {structure for KbdGetHWID}
  143. TKbdHWID=record
  144. cb,
  145. idKbd,
  146. usReserved1,
  147. usReserved2:word;
  148. end;
  149. PKbdHWID=^TKbdHWID;
  150. {structure for KbdXlate}
  151. (* #pragma pack(2) ???*)
  152. TKbdTrans=record
  153. chChar:char;
  154. chScan:byte;
  155. fbStatus:byte;
  156. bNlsShift:byte;
  157. fsState:word;
  158. time:longint;
  159. fsDD:word;
  160. fsXlate:word;
  161. fsShift:word;
  162. sZero:word;
  163. end;
  164. PKbdTrans=^TKbdTrans;
  165. {See KR_* constants for FnMask}
  166. function KbdRegister(ModuleName,ProcName:PChar;FnMask:longint):word;
  167. function KbdRegister(ModuleName,ProcName:string;FnMask:longint):word;
  168. {Deregister a keyboard subsystem previously registered within a session - only
  169. the process that issued the KbdRegister may issue KbdDeRegister}
  170. {Possible return codes:
  171. 0 NO_ERROR
  172. 411 ERROR_KBD_DEREGISTER
  173. 464 ERROR_KBD_DETACHED
  174. 504 ERROR_KBD_EXTENDED_SG}
  175. function KbdDeRegister:word;
  176. {Return a character data record from the keyboard}
  177. {Key - see TKbdKeyInfo, WaitFlag - see IO_WAIT and IO_NOWAIT constants,
  178. KbdHandle is the default keyboard (0) or a logical keyboard.}
  179. {Possible return codes are:
  180. 0 NO_ERROR
  181. 375 ERROR_KBD_INVALID_IOWAIT
  182. 439 ERROR_KBD_INVALID_HANDLE
  183. 445 ERROR_KBD_FOCUS_REQUIRED
  184. 447 ERROR_KBD_KEYBOARD_BUSY
  185. 464 ERROR_KBD_DETACHED
  186. 504 ERROR_KBD_EXTENDED_SG}
  187. {Remarks:
  188. * On an enhanced keyboard, the secondary enter key returns the normal
  189. character 0DH and a scan code of E0H.
  190. * Double-byte character codes (DBCS) require two function calls to obtain the
  191. entire code.
  192. * If shift report is set with KbdSetStatus, the CharData record returned
  193. reflects changed shift information only.
  194. * Extended ASCII codes are identified with the status byte, bit 1 on and the
  195. ASCII character code being either 00H or E0H. Both conditions must be
  196. satisfied for the character to be an extended keystroke. For extended
  197. ASCII codes, the scan code byte returned is the second code (extended
  198. code). Usually the extended ASCII code is the scan code of the primary key
  199. that was pressed.
  200. * A thread in the foreground session that repeatedly polls the keyboard with
  201. KbdCharIn (with no wait), can prevent all regular priority class threads
  202. from executing. If polling must be used and a minimal amount of other
  203. processing is being performed, the thread should periodically yield to the
  204. CPU by issuing a DosSleep call for an interval of at least 5 milliseconds.}
  205. function KbdCharIn(var Key:TKbdKeyInfo;WaitFlag,KbdHandle:word):word;
  206. function KbdPeek(var Key:TKbdKeyInfo;KbdHandle:word):word;
  207. function KbdStringIn(var CharBuf;var pchIn:TStringInBuf;WaitFlag:word;
  208. KbdHandle:word):word;
  209. {Clear the keystroke buffer}
  210. {KbdHandle is the default keyboard (0) or a logical keyboard.}
  211. {Possible return codes are:
  212. 0 NO_ERROR
  213. 439 ERROR_KBD_INVALID_HANDLE
  214. 445 ERROR_KBD_FOCUS_REQUIRED
  215. 447 ERROR_KBD_KEYBOARD_BUSY
  216. 464 ERROR_KBD_DETACHED
  217. 504 ERROR_KBD_EXTENDED_SG}
  218. {Remarks:
  219. * KbdFlushBuffer completes when the handle has access to the physical
  220. keyboard (focus), or is equal to zero and no other handle has the focus.}
  221. function KbdFlushBuffer(KbdHandle:word):word;
  222. function KbdSetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  223. function KbdGetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  224. function KbdSetCp(usReserved,CodePage,KbdHandle:word):word;
  225. {Query the code page being used to translate scan codes to ASCII characters.}
  226. {ulReserved must be set to 0. The keyboard support returns the current code
  227. page for a specified keyboard handle in CodePage, it is one of the code page
  228. IDs specified in the CONFIG.SYS CODEPAGE= statement or 0000. KbdHandle is
  229. the default keyboard (0) or a logical keyboard.}
  230. {Possible return codes:
  231. 0 NO_ERROR
  232. 373 ERROR_KBD_PARAMETER
  233. 439 ERROR_KBD_INVALID_HANDLE
  234. 445 ERROR_KBD_FOCUS_REQUIRED
  235. 447 ERROR_KBD_KEYBOARD_BUSY
  236. 464 ERROR_KBD_DETACHED
  237. 504 ERROR_KBD_EXTENDED_SG}
  238. {Remarks:
  239. * CodePage is set to the currently active keyboard code page. A value of 0
  240. indicates the code page translation table in use is the ROM code page
  241. translation table provided by the hardware.}
  242. function KbdGetCp(ulReserved:longint;var CodePage:word;KbdHandle:word):word;
  243. function KbdOpen(var KbdHandle:word):word;
  244. {Close the existing logical keyboard identified by the keyboard handle}
  245. {KbdHandle is the default keyboard (0) or a logical keyboard}
  246. {Possible return codes:
  247. 0 NO_ERROR
  248. 439 ERROR_KBD_INVALID_HANDLE
  249. 464 ERROR_KBD_DETACHED
  250. 504 ERROR_KBD_EXTENDED_SG}
  251. {Remarks:
  252. * KbdClose blocks while another thread has the keyboard focus (by way of
  253. KbdGetFocus) until the thread with the focus issues KbdFreeFocus.
  254. Therefore, to prevent KbdClose from blocking, it is recommended that
  255. KbdClose be issued only while the current thread has the focus. For
  256. example:
  257. KbdGetFocus Wait until focus available on handle 0.
  258. KbdClose Close a logical keyboard handle.
  259. KbdFreeFocus Give up the focus on handle 0.}
  260. function KbdClose(KbdHandle:word):word;
  261. {Bind the logical keyboard to the physical keyboard.}
  262. {KbdHandle is the default keyboard (0) or a logical keyboard}
  263. {Possible return codes:
  264. 0 NO_ERROR
  265. 439 ERROR_KBD_INVALID_HANDLE
  266. 445 ERROR_KBD_FOCUS_REQUIRED
  267. 464 ERROR_KBD_DETACHED
  268. 504 ERROR_KBD_EXTENDED_SG}
  269. function KbdGetFocus(WaitFlag,KbdHandle:word):word;
  270. {Free the logical-to-physical keyboard bond created by KbdGetFocus.}
  271. {KbdHandle is the default keyboard (0) or a logical keyboard}
  272. {Possible return codes:
  273. 0 NO_ERROR
  274. 439 ERROR_KBD_INVALID_HANDLE
  275. 445 ERROR_KBD_FOCUS_REQUIRED
  276. 464 ERROR_KBD_DETACHED
  277. 504 ERROR_KBD_EXTENDED_SG}
  278. {Remarks:
  279. * KbdFreeFocus may be replaced by issuing KbdRegister. Unlike other keyboard
  280. subsystem functions, the replaced KbdFreeFocus is called only if there is
  281. an outstanding focus.}
  282. function KbdFreeFocus(KbdHandle:word):word;
  283. function KbdSynch (WaitFlag:word):word;
  284. function KbdSetFgnd:word;
  285. function KbdGetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  286. function KbdSetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  287. function KbdXlate(var TransData:TKbdTrans;KbdHandle:word):word;
  288. function KbdSetCustXt(var XLateTbl;KbdHandle:word):word;
  289. (* Following routines are not supported
  290. (just have a look in some C header
  291. file - you probably won't find it there either).
  292. KbdInit (index 2)
  293. KbdLoadInstance (index 6)
  294. KbdSwitchFgnd (index 15)
  295. KbdShellInit (index 16)
  296. KbdFree (index 19)
  297. *)
  298. {***************************************************************************}
  299. implementation
  300. {***************************************************************************}
  301. function KbdRegister(ModuleName,ProcName:PChar;FnMask:longint):word;
  302. external 'EMXWRAP' index 208;
  303. {external 'KBDCALLS' index 8;}
  304. function KbdRegister(ModuleName,ProcName:string;FnMask:longint):word;
  305. var A1:array[0..8] of char;
  306. A2:array[0..32] of char;
  307. begin
  308. if byte(ModuleName[0])>8 then byte(ModuleName[0]):=8;
  309. StrPCopy(@A1,ModuleName);
  310. if byte(ProcName[0])>32 then byte(ProcName[0]):=32;
  311. StrPCopy(@A2,ProcName);
  312. KbdRegister:=KbdRegister(@A1,@A2,FnMask);
  313. end;
  314. function KbdDeRegister:word;
  315. external 'EMXWRAP' index 220;
  316. {external 'KBDCALLS' index 20;}
  317. function KbdCharIn(var Key:TKbdKeyInfo;WaitFlag,KbdHandle:word):word;
  318. external 'EMXWRAP' index 204;
  319. {external 'KBDCALLS' index 4;}
  320. function KbdPeek(var Key:TKbdKeyInfo;KbdHandle:word):word;
  321. external 'EMXWRAP' index 222;
  322. {external 'KBDCALLS' index 22;}
  323. function KbdStringIn(var CharBuf;var pchIn:TStringInBuf;WaitFlag:word;
  324. KbdHandle:word):word;
  325. external 'EMXWRAP' index 209;
  326. {external 'KBDCALLS' index 9;}
  327. function KbdFlushBuffer(KbdHandle:word):word;
  328. external 'EMXWRAP' index 213;
  329. {external 'KBDCALLS' index 13;}
  330. function KbdSetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  331. external 'EMXWRAP' index 211;
  332. {external 'KBDCALLS' index 11;}
  333. function KbdGetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  334. external 'EMXWRAP' index 210;
  335. {external 'KBDCALLS' index 10;}
  336. function KbdSetCp(usReserved,CodePage,KbdHandle:word):word;
  337. external 'EMXWRAP' index 205;
  338. {external 'KBDCALLS' index 5;}
  339. function KbdGetCp(ulReserved:longint;var CodePage:word;KbdHandle:word):word;
  340. external 'EMXWRAP' index 203;
  341. {external 'KBDCALLS' index 3;}
  342. function KbdOpen(var KbdHandle:word):word;
  343. external 'EMXWRAP' index 223;
  344. {external 'KBDCALLS' index 23;}
  345. function KbdClose(KbdHandle:word):word;
  346. external 'EMXWRAP' index 217;
  347. {external 'KBDCALLS' index 17;}
  348. function KbdGetFocus(WaitFlag,KbdHandle:word):word;
  349. external 'EMXWRAP' index 212;
  350. {external 'KBDCALLS' index 12;}
  351. function KbdFreeFocus(KbdHandle:word):word;
  352. external 'EMXWRAP' index 218;
  353. {external 'KBDCALLS' index 18;}
  354. function KbdSynch (WaitFlag:word):word;
  355. external 'EMXWRAP' index 207;
  356. {external 'KBDCALLS' index 7;}
  357. function KbdSetFgnd:word;
  358. external 'EMXWRAP' index 221;
  359. {external 'KBDCALLS' index 21;}
  360. function KbdGetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  361. external 'EMXWRAP' index 224;
  362. {external 'KBDCALLS' index 24;}
  363. function KbdSetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  364. external 'EMXWRAP' index 225;
  365. {external 'KBDCALLS' index 25;}
  366. function KbdXlate(var TransData:TKbdTrans;KbdHandle:word):word;
  367. external 'EMXWRAP' index 214;
  368. {external 'KBDCALLS' index 14;}
  369. function KbdSetCustXt(var XLateTbl;KbdHandle:word):word;
  370. external 'EMXWRAP' index 201;
  371. {external 'KBDCALLS' index 1;}
  372. end.