kbdcalls.pas 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  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 ([email protected] on Internet)
  32. Date: Description of change: Changed by:
  33. - First released version 1.0 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
  37. (I 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. {return codes / error constants (those marked with * shouldn't occur)}
  53. NO_ERROR = 0;
  54. ERROR_SEM_TIMEOUT =121;
  55. ERROR_KBD_PARAMETER =373;
  56. ERROR_KBD_NO_DEVICE =374; {*}
  57. ERROR_KBD_INVALID_IOWAIT =375; {*}
  58. ERROR_KBD_INVALID_LENGTH =376;
  59. ERROR_KBD_INVALID_ECHO_MASK =377;
  60. ERROR_KBD_INVALID_INPUT_MASK =378;
  61. ERROR_KBD_SMG_ONLY =407; {*}
  62. ERROR_KBD_INVALID_ASCIIZ =408;
  63. ERROR_KBD_INVALID_MASK =409;
  64. ERROR_KBD_REGISTER =410;
  65. ERROR_KBD_DEREGISTER =411;
  66. ERROR_KBD_INVALID_HANDLE =439;
  67. ERROR_KBD_NO_MORE_HANDLE =440;
  68. ERROR_KBD_CANNOT_CREATE_KCB =441;
  69. ERROR_KBD_CODEPAGE_LOAD_INCOMPL =442; {*}
  70. ERROR_KBD_INVALID_CODEPAGE_ID =443; {*}
  71. ERROR_KBD_NO_CODEPAGE_SUPPORT =444; {*}
  72. ERROR_KBD_FOCUS_REQUIRED =445;
  73. ERROR_KBD_FOCUS_ALREADY_ACTIVE =446; {*}
  74. ERROR_KBD_KEYBOARD_BUSY =447;
  75. ERROR_KBD_INVALID_CODEPAGE =448;
  76. ERROR_KBD_UNABLE_TO_FOCUS =449; {*}
  77. ERROR_KBD_DETACHED =464;
  78. ERROR_KBD_NO_CONSOLE =500; {*}
  79. ERROR_KBD_EXTENDED_SG =504;
  80. {FnMask}
  81. KR_KBDCHARIN =$00000001;
  82. KR_KBDPEEK =$00000002;
  83. KR_KBDFLUSHBUFFER =$00000004;
  84. KR_KBDGETSTATUS =$00000008;
  85. KR_KBDSETSTATUS =$00000010;
  86. KR_KBDSTRINGIN =$00000020;
  87. KR_KBDOPEN =$00000040;
  88. KR_KBDCLOSE =$00000080;
  89. KR_KBDGETFOCUS =$00000100;
  90. KR_KBDFREEFOCUS =$00000200;
  91. KR_KBDGETCP =$00000400;
  92. KR_KBDSETCP =$00000800;
  93. KR_KBDXLATE =$00001000;
  94. KR_KBDSETCUSTXT =$00002000;
  95. {WaitFlag}
  96. IO_WAIT =0;
  97. {KbdCharIn: wait for a character if one is not available}
  98. {KbdGetFocus: wait for the focus}
  99. {KbdStringIn: in binary input mode, wait until CharBuf is full, in }
  100. { ASCII input mode wait until a carriage return is pressed}
  101. IO_NOWAIT =1;
  102. {KbdCharIn: immediate return if no character is available}
  103. {KbdGetFocus: do not wait for the focus}
  104. {KbdStringIn: send an immediate return if no characters are available,}
  105. { if characters available, send them (up to the maximum }
  106. { length); not supported in ASCII input mode }
  107. {TKbdInfo.fsMask}
  108. KEYBOARD_ECHO_ON =$0001; {echo is on}
  109. KEYBOARD_ECHO_OFF =$0002; {echo is off}
  110. KEYBOARD_BINARY_MODE =$0004; {binary mode is on}
  111. KEYBOARD_ASCII_MODE =$0008; {ASCII mode is on}
  112. KEYBOARD_MODIFY_STATE =$0010; {shift state is modified}
  113. KEYBOARD_MODIFY_INTERIM =$0020; {interim character flags are modified}
  114. KEYBOARD_MODIFY_TURNAROUND =$0040; {turn-around character is modified}
  115. KEYBOARD_2B_TURNAROUND =$0080; {length of the turn-around character }
  116. {(meaningful only if }
  117. {KEYBOARD_MODIFY_TURNAROUND bit is on)}
  118. KEYBOARD_SHIFT_REPORT =$0100; {shift return is on}
  119. {TKbdInfo.fsState/TKbdKeyInfo.fsState/TKbdTrans.fsState}
  120. KBDSTF_RIGHTSHIFT =$0001;
  121. KBDSTF_LEFTSHIFT =$0002;
  122. KBDSTF_CONTROL =$0004;
  123. KBDSTF_ALT =$0008;
  124. KBDSTF_SCROLLLOCK_ON =$0010;
  125. KBDSTF_NUMLOCK_ON =$0020;
  126. KBDSTF_CAPSLOCK_ON =$0040;
  127. KBDSTF_INSERT_ON =$0080;
  128. KBDSTF_LEFTCONTROL =$0100;
  129. KBDSTF_LEFTALT =$0200;
  130. KBDSTF_RIGHTCONTROL =$0400;
  131. KBDSTF_RIGHTALT =$0800;
  132. KBDSTF_SCROLLLOCK =$1000;
  133. KBDSTF_NUMLOCK =$2000;
  134. KBDSTF_CAPSLOCK =$4000;
  135. KBDSTF_SYSREQ =$8000;
  136. {TKbdTrans.fbStatus}
  137. KBDTRF_SHIFT_KEY_IN =$01; {shift status returned}
  138. {without character }
  139. KBDTRF_EXTENDED_KEY_IN =$02; {extended key code }
  140. {from the keyboard,}
  141. {not a character }
  142. KBDTRF_CONVERSION_REQUEST =$20; {immediate conversion}
  143. {requested }
  144. KBDTRF_FINAL_CHAR_IN =$40; {either $40 or $80 or both}
  145. KBDTRF_INTERIM_CHAR_IN =$80; {must be present }
  146. type
  147. (*This should be removed as soon as cardinal arithmetic in FPC works OK.*)
  148. cardinal=longint;
  149. {TKbdKeyInfo - record type for character data for KbdCharIn and KbdPeek}
  150. (* #pragma pack(2) ??? *)
  151. TKbdKeyInfo=record
  152. chChar:char; {ASCII character code; the scan code received}
  153. {from the keyboard is translated to the ASCII}
  154. {character code }
  155. chScan:byte; {scan Code received from the keyboard}
  156. fbStatus:byte; {state of the keystroke event, see KBDTRF_*}
  157. bNlsShift:byte; {NLS shift status (always 0?)}
  158. fsState:word; {shift key status, see KBDSTF_*}
  159. Time:cardinal; {time stamp indicating when a key was pressed,}
  160. {specified in milliseconds from the time }
  161. {the system was started }
  162. end;
  163. PKbdKeyInfo=^TKbdKeyInfo;
  164. {record type for KbdStringIn}
  165. TStringInBuf=record
  166. cb:word; {length of the input buffer, maximum length is 255}
  167. cchIn:word; {number of bytes actually read into the buffer}
  168. end;
  169. PStringInBuf=TStringInBuf;
  170. {TKbdInfo record type, for KbdSet/GetStatus}
  171. TKbdInfo=record
  172. cb, {total length in bytes, 10 is the only valid value }
  173. fsMask, {see TKbdInfo.fsMask constants, higher bits reserved}
  174. {and set to 0 }
  175. chTurnAround, {definition of the turn-around character, in ASCII }
  176. {and extended-ASCII format, the turn-around character}
  177. {is defined as the carriage return, in ASCII format }
  178. {only, the turn-around character is defined in the }
  179. {low-order byte; usually $000D }
  180. fsInterim, {interim character flags: bits 0-4 and 6 - reserved }
  181. { and set to 0,}
  182. { bit 5 - application}
  183. { requested }
  184. { immediate }
  185. { conversion }
  186. { bit 7 - interim }
  187. { character }
  188. { flag is on }
  189. { bits 8-15 - NLS shift }
  190. { state }
  191. fsState:word; {shift state, see TKbdInfo.fsState constants}
  192. end;
  193. PKbdInfo=^TKbdInfo;
  194. {record type for KbdGetHWID}
  195. TKbdHWID=record
  196. cb, {length in bytes, on input length of the TKbdHWID}
  197. {record (at least 2), on output the actual number}
  198. {of bytes returned }
  199. idKbd, {keyboard type: $0000 = undetermined keyboard type}
  200. { $0001 = PC-AT Standard Keyboard }
  201. { $AB41 = 101 Key Enhanced Keyboard }
  202. { $AB41 = 102 Key Enhanced Keyboard }
  203. { $AB54 = 88 and 89 Key Enhanced }
  204. { Keyboards }
  205. { $AB85 = 122 Key Enhanced Keyboard }
  206. usReserved1, {reserved, returned set to zero (secondary ID?)}
  207. usReserved2:word; {reserved, returned set to zero}
  208. end;
  209. PKbdHWID=^TKbdHWID;
  210. {record type for KbdXlate}
  211. (* #pragma pack(2) ???*)
  212. TKbdTrans=record
  213. case boolean of
  214. false:(
  215. CharData:TKbdKeyInfo);
  216. true:(
  217. chChar:char; {ASCII character code; the scan code received}
  218. {from the keyboard is translated to the ASCII}
  219. {character code }
  220. chScan:byte; {scan Code received from the keyboard}
  221. fbStatus:byte; {state of the keystroke event, see KBDTRF_*}
  222. bNlsShift:byte; {NLS shift status (always 0?)}
  223. fsState:word; {shift key status, see KBDSTF_*}
  224. Time:cardinal; {time stamp indicating when a key was pressed,}
  225. {specified in milliseconds from the time }
  226. {the system was started }
  227. fsDD:word; {device driver returned flag,}
  228. {see KbdDDFlagWord notes }
  229. fsXlate:word; {translation flag: 0 - translation incomplete,}
  230. { 1 - translation complete }
  231. fsShift:word; {identifies the state of translation across }
  232. {successive calls, initially the value should }
  233. {be zero; it may take several calls to this }
  234. {function to complete a character, the value }
  235. {should not be changed unless a new translation}
  236. {is required (that is, reset value to zero) }
  237. sZero:word); {reserved, set to 0}
  238. end;
  239. PKbdTrans=^TKbdTrans;
  240. {KbdDDFlagWord notes:
  241. bits 15-14 Available. These bits are available for communication between
  242. monitors; they are not used by the physical device driver. The
  243. monitor applications coordinate the use of these flags.
  244. Bits 13-10 Reserved, set to zero. Monitors must pass these flags as is.
  245. They must set these flags to 0 in packets they create.
  246. Bit 9 Accented. This key is translated using the previous key passed,
  247. which is an accent key. Where an accent key is pressed, and the
  248. following key does not use the accent, a packet containing the
  249. accent character itself is first passed with this bit set. The
  250. scan code field of MonFlagWord (see above) would be 0,
  251. indicating a non-key generated record. A valid packet
  252. containing that following keystroke is then passed without this
  253. bit set.
  254. Bit 8 Multimake. The translation process sees this scan code as
  255. a typematic repeat of a toggle key or a shift key. Because
  256. toggle and shift keys only change state on the first make after
  257. each key-break, no state information is changed. For example,
  258. the NumLock toggle bit in the shift status word is not changed,
  259. even though this can be the NumLock key. If this key is a valid
  260. character, it does not go into the Keyboard Input Buffer (KIB)
  261. once this bit is set.
  262. Bit 7 Secondary. The scan code prior to the one in this packet was
  263. the Secondary Key Prefix (see below).
  264. Bit 6 Key break. This record is generated by the release (the break)
  265. of the key involved.
  266. Bits 5-0 Key type. This numeric field flags the physical device driver
  267. and reports that this is a key that requires action. The number
  268. in this field is filled in during the translation of the scan
  269. code. The value allows the driver to act on keystrokes without
  270. regard for what scan codes the keyboard uses or character codes
  271. that the current translation process may be using. The
  272. following values are currently defined:
  273. - Value for keys that are always placed in the KIB.
  274. Zero = no special action, always place in KIB.
  275. - Values acted on prior to passing packet to monitors.
  276. Except for the final keystroke of the DUMP key sequences,
  277. all of these values are passed on to the monitors. They
  278. are not placed in the KIB. The XlatedChar and XlatedScan
  279. fields are undefined for these values:
  280. 01h ACK. This scan code is a keyboard acknowledge.
  281. Personal Computer IBM* AT* attached keyboards
  282. set this value on an FAh scan code.
  283. 02h Secondary key prefix. This scan code is a prefix
  284. generated by the Enhanced Keyboard. It indicates
  285. that the next scan code coming is one of the
  286. secondary keys that exists on that keyboard.
  287. Usually set on an E0h scan code or an E1h scan
  288. code.
  289. 03h Kbd overrun. This scan code is an overrun
  290. indication from the keyboard. On an IBM Personal
  291. Computer AT-attached keyboard, this value would be
  292. set on an FFh scan code.
  293. 04h Resend. This scan code is a resend request from the
  294. keyboard. On an IBM Personal Computer AT-attached
  295. keyboard, this value would be set on an FEh scan
  296. code.
  297. 05h Reboot key. This scan code completes the multi-key
  298. restart sequence. On an IBM Personal Computer AT
  299. attached-keyboard, this value would be used when
  300. the Ctrl+Alt+Delete sequence is used.
  301. 06h Dump key. This scan code completes the multi-key
  302. Stand Alone Dump request sequence. On an IBM
  303. Personal Computer AT-attached keyboard, this value
  304. would be used on completion of the second
  305. consecutive press of Ctrl+Alt+NumLock or
  306. Ctrl+Alt+F10 without other keystrokes between the
  307. two presses.
  308. 07h-
  309. 0Ah See entries below.
  310. 0Bh Invalid accent combination. This scan code follows
  311. an accent scan code but the combination is not
  312. valid, and neither key is put in the KIB.
  313. (Note: This is set if the Canadian-French code
  314. pages are in use.)
  315. 0Ch System-defined hot keys.
  316. 0Dh
  317. -0Fh Reserved. Treated as undefined. See entry 3Fh.
  318. - Values acted on after passing packet to monitors. Except
  319. where noted, these values are placed in the KIB when the
  320. physical device driver is in binary mode; they are not
  321. placed in the KIB when the physical device driver is in
  322. ASCII mode. (Also listed are those that never get placed
  323. in the KIB.)
  324. 07h Shift key. This scan code translates as a shift key
  325. and affects the shift status fields of the CharData
  326. record, but does not generate a defined character.
  327. It is not placed in the KIB. The XlatedChar field
  328. is undefined. The scan code field is 0.
  329. 08h Pause key. This scan code is translated as the key
  330. sequence meaning pause. On an IBM Personal Computer
  331. AT-attached keyboard, this value is used when the
  332. Ctrl+NumLock sequence is used. The key itself is
  333. not placed in the KIB.
  334. 09h Pseudo-Pause key. This scan code is translated into
  335. the value that is treated as the Pause key when the
  336. physical device driver is in ASCII mode. On most
  337. keyboards, this would be when the Ctrl+S
  338. combination is used. The key itself is not placed
  339. in the KIB.
  340. 0Ah Wake-up key. This scan code follows a Pause key or
  341. Pseudo-Pause key, which causes the Pause state to
  342. end. The key itself is not placed in the KIB.
  343. 10h Accent key. This scan code is translated and used
  344. as a key to alter the translation of the next key
  345. to come in. The packet containing this value is
  346. passed when the accent key is pressed, but it is
  347. not put into the KIB, unless the Accented bit is
  348. ON. The next key determines this decision. If the
  349. next key is one that can be accented, then it is
  350. passed by itself with the Accented bit ON. If that
  351. next key cannot be accented by this accent, then
  352. two packets are passed. The first contains the
  353. character to print for the accent itself. It has
  354. the Accent key value and the Accented flag (which
  355. allows the packet to be put in the KIB). The second
  356. packet contains a regular translation of that
  357. following key.
  358. (Note: The two packets get passed for every
  359. language except Canadian-French - see entry 0Bh.)
  360. 11h Break key. This scan code is translated as the key
  361. sequence meaning break. On the IBM Personal
  362. Computer AT-attached keyboard, this value is used
  363. where the Ctrl+Break sequence is used.
  364. 12h Pseudo-Break key. This scan code is translated into
  365. the value that is treated as the Break key when the
  366. physical device driver is in ASCII mode. On most
  367. keyboards, this would be when the Ctrl+C
  368. combination is used. Notice that the event
  369. generated by this key is separate from the one
  370. generated by the Break key when in the binary mode.
  371. 13h Print Screen key. This scan code is translated as
  372. the key sequence meaning Print Screen. On an IBM
  373. Personal Computer AT-attached keyboard, this value
  374. is used where the Shift+PrtSc sequence is used.
  375. 14h Print Echo key. This scan code is translated as the
  376. key sequence meaning Print Echo. This value is used
  377. where the Ctrl+PrtSc sequence is used.
  378. 15h Pseudo-Print Echo key. This scan code is translated
  379. into the value that is treated as the Print Echo
  380. key when the physical device driver is in ASCII
  381. mode. On most keyboards, this would show as the
  382. Ctrl+P combination.
  383. 16h Print-Flush key. This scan code is translated into
  384. the key sequence Print-Flush. This value is used
  385. where the Ctrl+Alt+PrtSc sequence is used.
  386. 17h
  387. -2Fh Reserved, set to zero. Treated as undefined. See
  388. entry 3Fh.
  389. - Values for packets not generated by a keystroke:
  390. 30h
  391. -37h Reserved.
  392. 38h
  393. -3Eh Reserved. Treated as undefined. See entry 3Fh.
  394. - Value for keys the translation process does not recognize:
  395. 3Fh Undefined. This scan code, or its combination with
  396. the current shift state, is not recognized in the
  397. translation process.
  398. }
  399. {header of TXLateTbl}
  400. TXHeader=record
  401. XTableID:word; {code page number}
  402. XTableFlags1:word; {bits 0-2 determine which shift key or key }
  403. {combination affects Char3 of each TXLateKeyDef }
  404. {element, bits 7-10 determine which shift key or}
  405. {key combination causes Char5 to be used in each}
  406. {TXLateKeyDef element }
  407. {bit 0 - ShiftAlt (use Shift+Alt instead of }
  408. { Ctrl+Alt) }
  409. {bit 1 - AltGrafL (use left Alt key as }
  410. { Alt+Graphics) }
  411. {bit 2 - AltGrafR (use right Alt key as }
  412. { Alt+Graphics) }
  413. {bit 3 - ShiftLock (treat Caps Lock as }
  414. { ShiftLock) }
  415. {bit 4 - DefaultTable (default table for the }
  416. { language) }
  417. {bit 5 - ShiftToggle (1 = toggle ShiftLock, }
  418. { 0 = latch it) }
  419. {bit 6 - AccentPass (pass accent and non-accent }
  420. { key through; 1 = pass on accent keys}
  421. { and beep, 0 = beep only }
  422. {bit 7 - CapsShift (Caps+Shift uses Char5) }
  423. {bit 8 - MachDep (machine-dependent table) }
  424. {bits 9-10 reserved }
  425. {bits 11-15 reserved }
  426. XTableFlags2:word; {reserved, set to zero}
  427. KbdType:word; {keyboard type, 1 for extended (all common types)}
  428. KbdSubType:word; {reserved}
  429. XtableLen:word; {length of table}
  430. EntryCount:word; {number of KeyDef entries}
  431. EntryWidth:word; {width of KeyDef entries}
  432. Country:word; {language ID}
  433. TableTypeID:word; {the table type; 1st byte (type): 01X 00X }
  434. { 2nd byte (sub-type): 00X reserved}
  435. SubCountryID:cardinal;
  436. {sub-language identifier}
  437. Reserved:array[1..8] of word;
  438. end;
  439. PXHeader=^TXHeader;
  440. {element of TXLateTbl, not all entries are used (unused entries are zero)}
  441. TXLateKeyDef=record
  442. XlateOp:word; {translate operation specifier; }
  443. {bits 0- 6 - AccentFlags (see Notes 1 and 8)}
  444. {bits 7-15 - KeyType (see Note 2) }
  445. Char1:char;
  446. Char2:char;
  447. Char3:char;
  448. Char4:char;
  449. Char5:char;
  450. end;
  451. PXLateKeyDef=^TXLateKeyDef;
  452. {record type for character definition in TAccentEntry}
  453. TKeyCode=record
  454. CharCode:char;
  455. ScanCode:byte;
  456. end;
  457. {accent entry definitions for TAccentTable, see Notes 1 and 9}
  458. TAccentEntry=record
  459. NonAccent:TKeyCode; {char/scan code when}
  460. {not used as accent }
  461. CtlAccent:TKeyCode; {char/scan code when}
  462. {used with Ctrl key }
  463. AltAccent:TKeyCode; {char/scan code when}
  464. {used with Alt key }
  465. Maps:array[1..20] of TKeyCode; {from char-to-char for translation}
  466. end;
  467. PAccentEntry=^TAccentEntry;
  468. {table of accent key definitions for TXLateTbl}
  469. TAccentTable=array[1..7] of TAccentEntry;
  470. PAccentTable=^TAccentTable;
  471. {record type for SetCustXT, one element for each possible scan code
  472. (entries are in scan code order, based on the remapped scan codes
  473. returned by the keyboard controller)}
  474. TXLateTbl=record
  475. XHeader:TXHeader;
  476. KeyDefs:array [1..127] of TXLateKeyDef;
  477. AccentTbl:TAccentTable;
  478. end;
  479. PXLateTbl=^TXLateTbl;
  480. {Remarks for TXLateTbl record type:
  481. The request changes the device driver resident code page for the system
  482. and updates the zero entry of the Code Page Control Block.
  483. * Note 1
  484. The AccentFlags field of the KeyDef record has seven flags that are
  485. individually set if a corresponding entry in the accent table applies to this
  486. scan code. If the key pressed immediately before the current one was an
  487. accent key and the bit for that accent is set in the AccentFlags field for
  488. the current key, the corresponding AccentTable entry is searched for the
  489. replacement character value to use. If no replacement is found and bit 6 of
  490. the XlateFlags1 field is set, the not-an-accent beep is sounded and the
  491. accent character and current character are passed as two separate
  492. characters. Also see Note 8.
  493. * Note 2
  494. The KeyType field of the KeyDef record currently has the following values
  495. defined. The remaining values up to 1Fh are undefined. The effect of each
  496. type of shift is defined below. Except where otherwise noted, when no
  497. shifts are active, Char1 is the translated character. (See Note 3.) Notice
  498. that any of the Alt, Alt+Char, Alt+Shift, or Alt+Gr keys (or all of them) can
  499. be present on a keyboard based on the AltGrafL and AltGrafR bits in the
  500. XTableFlags1 flag word in the table header.
  501. 01h AlphaKey. Alphabetical character key:
  502. Shift Uses Char2. If Caps Lock, uses Char1.
  503. Caps Lock Uses Char2. If Shift, uses Char1.
  504. Ctrl Set standard control code for this key's Char1 value.
  505. See Note 4.
  506. Alt Standard extended code. See Note 7.
  507. Alt+Char Uses Char3, if it is not 0.
  508. Alt+Shift Uses Char3, if it is not 0.
  509. Alt+Gr Uses Char3, if it is not 0.
  510. 02h SpecKey. Special nonalphabetic character key, no Caps Lock or Alt:
  511. Shift Uses Char2.
  512. Caps Lock No effect, only depends on Shift, or Ctrl.
  513. Ctrl See Note 4.
  514. Alt Marked undefined.
  515. Alt+Char Uses Char3, if it is not 0.
  516. Alt+Shift Uses Char3, if it is not 0.
  517. Alt+Gr Uses Char3, if it is not 0.
  518. 03h SpecKeyC. Special nonalphabetic character key with Caps Lock. See
  519. Note 15.
  520. Shift Uses Char2. If Caps Lock, uses Char1.
  521. Caps Lock Uses Char2. If Shift, uses Char1.
  522. Ctrl See Note 4.
  523. Alt Uses Char4, if not zero. See Note 7.
  524. Alt+Char Uses Char3, if it is not 0.
  525. Alt+Shift Uses Char3, if it is not 0.
  526. Alt+Gr Uses Char3, if it is not 0.
  527. 04h SpecKeyA. Special nonalphabetic character key with Alt (no Caps
  528. Lock):
  529. Shift Uses Char2.
  530. Caps Lock No effect; depends on Shift, Ctrl, or Alt only.
  531. Ctrl See Notes 5 and 9.
  532. Alt See Notes 7 and 10.
  533. Alt+Char Uses Char3, if it is not 0.
  534. Alt+Shift Uses Char3, if it is not 0.
  535. Alt+Gr Uses Char3, if it is not 0.
  536. 05h SpecKeyCA. Special nonalphabetic character key with Caps Lock and
  537. Alt:
  538. Shift Uses Char2. If Caps Lock, uses Char1.
  539. Caps Lock Uses Char2. If Shift, uses Char1.
  540. Ctrl See Note 4.
  541. Alt See Note 7.
  542. Alt+Char Uses Char3, if it is not 0.
  543. Alt+Shift Uses Char3, if it is not 0.
  544. Alt+Gr Uses Char3, if it is not 0.
  545. 06h FuncKey. Function keys. Char1 = n in Fn; Char2 ignored. Sets
  546. extended codes 58+Char1, if no shift; if F11 or F12, uses 139 and 140.
  547. Shift Sets extended codes 83+Char1. F11 and F12 use 141
  548. and 142, respectively.
  549. Caps Lock No effect on function keys.
  550. Ctrl Sets extended codes 93+Char1. F11 and F12 use 143
  551. and 144, respectively.
  552. Alt Sets extended codes 103+Char1. F11 and F12 use 145
  553. and 146, respectively.
  554. Alt+Char Uses Char3, if it is not 0.
  555. Alt+Shift Uses Char3, if it is not 0.
  556. Alt+Gr Uses Char3, if it is not 0.
  557. 07h PadKey. Keypad keys (see Note 5 for definition of Char1). Note that
  558. nonshifted use of these keys is fixed to the extended codes:
  559. Shift Uses Char2, unless Num Lock. See Note 5.
  560. Caps Lock No effect on pad keys, unless Num Lock. See Note 5.
  561. Ctrl Sets extended codes. See Note 5.
  562. Alt Used to build a character. See Note 5.
  563. Alt+Char Uses Char3, if it is not 0.
  564. Alt+Shift Uses Char3, if it is not 0.
  565. Alt+Gr Uses Char3, if it is not 0.
  566. 08h SpecCtlKey. Special action keys, when used with Ctrl pressed:
  567. Shift No effect on these keys.
  568. Caps Lock No effect on these keys.
  569. Ctrl Uses Char2.
  570. Alt See Note 7.
  571. Alt+Char Uses Char3, if it is not 0.
  572. Alt+Shift Uses Char3, if it is not 0.
  573. Alt+Gr Uses Char3, if it is not 0.
  574. 09h PrtSc. Print Screen key; sets Char1 normally (see Note 17):
  575. Shift Signal the Print Screen function.
  576. Caps Lock No effect on this key.
  577. Ctrl Sets extended code and signals the Print Echo function.
  578. Alt Marked undefined.
  579. Alt+Char Uses Char3, if it is not 0.
  580. Alt+Shift Uses Char3, if it is not 0.
  581. Alt+Gr Uses Char3, if it is not 0.
  582. 0Ah SysReq. System Request key; treated like a shift key. See Note 6.
  583. 0Bh AccentKey. Keys that affect the next key pressed (also known as
  584. dead keys). Char1 is an index into the AccentTbl field of the
  585. XlateTable, selecting the AccentEntry that corresponds to this key.
  586. Char2 and Char3 do the same for the shifted Accent character. See
  587. Note 15.
  588. Shift Uses Char2 to index to applicable AccentEntry.
  589. Caps Lock No effect on this key.
  590. Ctrl Uses CtlAccent character from AccentEntry. See Note 8.
  591. Alt Uses AltAccent character from AccentEntry. See Note 8.
  592. Alt+Char Uses Char3 to index to applicable AccentEntry.
  593. Alt+Shift Uses Char3 to index to applicable AccentEntry.
  594. Alt+Gr Uses Char3 to index to applicable AccentEntry.
  595. Note: Key types 0Ch - 13h set Char1 and Char2 to mask values as defined
  596. in Note 6.
  597. 0Ch ShiftKeys. Shift or Ctrl key, sets and clears flags. Char1 holds the
  598. bits in the lower byte of the shift status word to set when the
  599. key is down and clear when the key is released. Char2 does the
  600. same thing for the upper byte of the shift status word unless the
  601. secondary key prefix (hex E0) is seen immediately prior to this key,
  602. in which case Char3 is used in place of Char2.
  603. 0Dh ToggleKey. General toggle key (like Caps Lock). Char1 holds the
  604. bits in the lower byte of the shift status word to toggle on the
  605. first make of the key after it is pressed. Char2 holds the bits in
  606. the upper byte of the shift status word to set when the key is
  607. down and clear when the key is released unless the secondary key
  608. prefix (hex E0) is seen immediately prior to this key, in which case
  609. Char3 is used in place of Char2.
  610. 0Eh AltKey. Treated just like ShiftKeys above, but has its own key
  611. type, because when seen, the accumulator used for Alt+PadKey
  612. entry is zeroed to prepare such entry (see Note 5). Sometimes this
  613. key is treated as the AltC/S/G key (that is, either Alt+Char,
  614. Alt+Shift, or Alt+Gr) if one of the AltGraf bits is on in XTableFlags1.
  615. 0Fh Num Lock. Normally behaves like ToggleKey, but the physical
  616. keyboard device driver sets a pause screen indication when this
  617. key is used with the Ctrl key pressed. The pause is cleared on the
  618. following keystroke if that stroke is a character-generating key.
  619. 10h Caps Lock. This key is treated as a type 0Dh toggle key. It has a
  620. separate entry here so that it can be processed like a Shift Lock
  621. key when that flag is set in the XTableFlags1 word in the header.
  622. When treated as a Shift Lock, the Caps Lock flag in the shift
  623. status word is set on on any make of this key, and only cleared
  624. when the left or right shift key is pressed. Char2 and Char3 are
  625. processed the same as ToggleKey.
  626. 11h Scroll Lock. Normally behaves like ToggleKey but has a separate
  627. entry here. When used with Ctrl, it can be recognized as
  628. Ctrl+Break.
  629. 12h XShiftKey. Extended Shift Key (for Country support). See Note 9.
  630. 13h XToggleKey. Extended Toggle Key (for Country support). See Note 9.
  631. 14h SpecKeyCS. Special key 1 for country keyboard processing. See Note 15.
  632. Shift Uses Char2.
  633. Caps Lock Uses Char4.
  634. Ctrl See Note 4.
  635. Alt See Note 7.
  636. Alt+Char Uses Char3.
  637. Alt+Shift Uses Char3.
  638. Alt+Gr Uses Char3.
  639. Caps+Shift Uses Char5.
  640. 15h SpecKeyAS. Special key 2 for country keyboard processing. See Note 15.
  641. Shift Uses Char2.
  642. Caps Lock No effect on this key.
  643. Ctrl See Note 4.
  644. Alt Uses Char 4. See Note 14.
  645. Alt+Char Uses Char 3. See Note 14.
  646. Alt+Shift Uses Char 3. See Note 14.
  647. Alt+Gr Uses Char 3. See Note 14.
  648. 1Ah Extended Extended key. This corresponds to the BIOS level support
  649. provided for INT 16h, Functions 20h, 21h, and 22h.
  650. Shift Uses Char2.
  651. Caps Lock No effect on this key.
  652. Ctrl Uses Char4.
  653. Alt Uses Char5.
  654. Alt+Char Uses Char 3, if not 0.
  655. Alt+Shift Uses Char 3, if not 0.
  656. Alt+Gr Uses Char 3, if not 0.
  657. 16h-
  658. 1FFh Reserved, except for 1Ah, the Extended Extended key (see above).
  659. * Note 3
  660. Undefined Character Code. Any key combination that does not fall into any
  661. of the defined categories. For example, the Ctrl key pressed along with a
  662. key that has no defined control mapping is mapped to the value 0, and the
  663. key type is set in the KeyPacket record indicating undefined translation.
  664. The KeyPacket record passed to the monitors, if installed, contain the
  665. original scan code in the ScanCode field and the 0 in the Character field for
  666. this key. Notice that no character data records with an undefined character
  667. code are placed in the keyboard input buffer.
  668. * Note 4
  669. Ctrl Key. The six possible situations that can occur when a key is pressed
  670. with only the Ctrl+shift key are shown below:
  671. - The key pressed is an AlphaKey character. In this case, the Ctrl plus
  672. Char1 combination defines one of the standard defined control codes
  673. (all numbers are decimal):
  674. Ctrl- Mapping Code Name Ctrl- Mapping Code Name
  675. ----- ------- --------- ----- ------- ---------
  676. a 1 SOH n 14 SO
  677. b 2 STX o 15 SI
  678. c 3 ETX p 16 DLE
  679. d 4 EOT q 17 DC1
  680. e 5 ENQ r 18 DC2
  681. f 6 ACK s 19 DC3
  682. g 7 BEL t 20 DC4
  683. h 8 BS u 21 NAK
  684. i 9 HT v 22 SYN
  685. j 10 LF w 23 ETB
  686. k 11 VT x 24 CAN
  687. l 12 FF y 25 EM
  688. m 13 CR z 26 SUB
  689. Notice that any key defined as AlphaKey uses the Char1 code value
  690. minus 96 (ASCII code for a) plus 1 to set the mapping shown above.
  691. Any scan code defined as AlphaKey must assign to Char1 one of the
  692. allowed lower case letters.
  693. - The key pressed is a nonalpha character, such as [, but is not an action
  694. key, such as Enter, Backspace, or an arrow key. This is a
  695. SpecKey[C][A] in the list of key types in the previous example. In this
  696. case, with one exception, the mapping is based on the scan code of the
  697. key. Though the key can be relabeled, the Ctrl+Char combination is
  698. always mapped based on the scan code of the key using the following
  699. table (all numbers are decimal):
  700. }(*
  701. Scan US Kbd Mapped Name of
  702. Code Legend Value New Code
  703. ---- ------ ------ --------
  704. 3 2 @ 0 Null
  705. 7 6 ^ 30 RS
  706. 12 - _ 31 US (see Note below)
  707. 26 [ { 27 Esc
  708. 27 ] } 29 GS
  709. 43 \ | 28 FS
  710. *){
  711. Note: The mapping for the hyphen character (-) is the one exception.
  712. The scan code for it is ignored; only the ASCII code for hyphen
  713. (decimal 45) is looked for in Char1 when mapping the Ctrl+-
  714. combination. This is because there can be more than one
  715. occurrence of the hyphen (-) key on the keyboard. The Ctrl+-
  716. (PadKey minus) combination produces character/scan code values
  717. of 00/8Eh, respectively.
  718. - The key pressed is an action key such as Enter, Backspace, or an arrow
  719. key. These keys generate special values when used in conjunction with
  720. the Ctrl key. Those actions are defined in other notes where they
  721. apply. Two particular keys in this category are:
  722. Ctrl+Enter = LF(010)
  723. Ctrl+Backspace = Del(127)
  724. - The key pressed is a function key, F1 - F12. See the FuncKey
  725. description in Note 2.
  726. - The key pressed is an accent key. See Note 8.
  727. - The key is not defined in conjunction with Ctrl. In this case, the key
  728. is treated as undefined, as described in Note 3.
  729. * Note 5
  730. PadKey. The pad keys have several uses that depend on various shift
  731. states. Some of them are based on their position on the keyboard. Because
  732. keyboard layouts change, the hard-coded assumed positions of the keypad
  733. keys, with the offset value that must be coded into Char1, are defined
  734. below. Any remapping must use the Char1 values shown below for the keys
  735. that correspond to the pad keys given by the Legend or Char2 values:
  736. US Kbd Scan Char1 Char2
  737. Legend Code Required US Kbd With Ctrl
  738. ------- ---- --------- ------- -----------
  739. Home 7 71 Decimal 0 ASCII 7 Decimal 119
  740. Up 8 72 " 1 " 8 " 141
  741. PgUp 9 73 " 2 " 9 " 132
  742. - 74 " 3 " - " 142
  743. Left 4 75 " 4 " 4 " 115
  744. 5 76 " 5 " 5 " 143
  745. Right 6 77 " 6 " 6 " 116
  746. + 78 " 7 " + " 144
  747. End 1 79 " 8 " 1 " 117
  748. Down 2 80 " 9 " 2 " 145
  749. PgDn 3 81 " 10 " 3 " 118
  750. Ins 0 82 " 11 " 0 " 146
  751. Del . 83 " 12 " . " 147
  752. Notice that when Num Lock is off, or if Shift is active and Num Lock on, the
  753. code returned is the extended code. The code returned corresponds to the
  754. Legends above (Home, PgUp, and so forth). When Num Lock is on, or if
  755. Shift is active and Num Lock is off, the code returned is Char2. Notice that
  756. the + and - keys also return Char2 when the shift key is down.
  757. When the Alt key is used with the PadKeys, the absolute value of the
  758. pressed key (looked up using the required Char1 value) is added to the
  759. accumulated value of any of the previous numeric keys pressed, without
  760. releasing the Alt key. Before adding the new number to the accumulated
  761. value, that accumulation is multiplied by ten, with overflow beyond 255
  762. ignored. When Alt is released, the accumulation becomes a Character code
  763. and is passed along with a scan code of zero. Notice that if any key other
  764. than the 10 numeric keys is pressed, the accumulated value is reset to zero.
  765. When the keypad *, -, or + keys are pressed while the Alt key is down, the
  766. extended characters 55, 74, and 78 (decimal) are returned, respectively.
  767. When AltGraphics is used with the PadKeys, the Char3 value is returned if it
  768. is nonzero, and if an AltGraf bit is set in XTableFlags1; otherwise, it is
  769. treated the same as the Alt key.
  770. On the Enhanced keyboard, the secondary keypad keys return, as an
  771. extended character, the scan code of the key plus 80 (decimal) when
  772. pressed in conjunction with the Alt key. The secondary / key returns an
  773. extended character of 164, when pressed in conjunction with the Alt key.
  774. * Note 6
  775. State Key. Each state key entry has Char1, Char2, and Char3 defined as
  776. follows:
  777. - Char1. A mask to set the appropriate bit in the low byte of the
  778. keyboard Shift Flags when the state key is pressed. When the state
  779. key is a toggle key, the set bit is toggled each additional time the key
  780. is pressed. When the state key is not a toggle key, the set bit is
  781. cleared when the key is released.
  782. - Char2. A mask to set the appropriate bit in the high byte of the
  783. Keyboard Shift Flags when the key is pressed.
  784. - Char3. Used in place of Char2 when the secondary key prefix is seen
  785. immediately prior to this key.
  786. The masks are shown below (numbers are in hex):
  787. Key Char1 Char2 Char3
  788. ----------- ----- ----- -----
  789. Right Shift 01 00 00
  790. Left Shift 02 00 00
  791. Ctrl Shift 04 01 04
  792. Alt Shift 08 02 08
  793. Scroll Lock 10 10 10
  794. Num Lock 20 20 20
  795. Caps Lock 40 40 40
  796. SysReq 00 80 80
  797. Notice that the INS key is not treated as a state key, but as a pad key.
  798. Also, SysReq is included here because it is treated as a shift key.
  799. * Note 7
  800. Alt Character. Most of the keys defined in a category that allows the Alt
  801. key (AlphaKey, SpecKeyA, SpecKeyCA) return a value called an extended
  802. character. This value is a character code of 00H or E0H, with a second byte
  803. (using the ScanCode field of the CharData record) defining the extended
  804. code. In most cases, this value is the scan code of the key. Since the
  805. legend on these keys can be remapped on a foreign language keyboard, the
  806. Alt-based extended code is hard to define in a general sense. The following
  807. rules are used:
  808. - AlphaKey. The extended code is derived from Char1 (the lower-case
  809. character) as it was originally mapped on the PC keyboard. The
  810. original scan code value is the extended code that a character returns.
  811. These keys can be moved and will still return their original Alt
  812. extended codes.
  813. - SpecKeyA and SpecKeyCA. This category is used for all keys that are
  814. not an alphabetic character or an action code (like Enter or Backspace,
  815. the only exception being the Tab key, which is treated as a character).
  816. On foreign keyboards, these keys can be moved around and can have
  817. new values assigned to them, such as special punctuation symbols.
  818. Therefore, the Alt mappings must be based on the real scan code as
  819. any keys defined by the SpecKey_ classification will have only an Alt
  820. mapping, if it is in one of the positions defined below. In that case,
  821. the Alt extended code is as shown:
  822. }(*
  823. Scan US Kbd Alt Scan US Kbd Alt
  824. Code Legend Value Code Legend Value
  825. ---- ------ ----- ---- ------ -----
  826. 2 1 ! 120 15 Tab 165
  827. 3 2 @ 121 26 [ { 26
  828. 4 3 # 122 27 ] } 27
  829. 5 4 $ 123 28 Enter 28
  830. 6 5 % 124 39 ; : 39
  831. 7 6 ^ 125 40 ' " 40
  832. 8 7 & 126 41 ' ~ 41
  833. 9 8 * 127 43 \ | 43 (equals W.T.C. key number 42)
  834. 10 9 ( 128 51 , < 51
  835. 11 0 ) 129 52 . > 52
  836. 12 - _ 130 53 / ? 53
  837. 13 = + 131
  838. *){
  839. The secondary / key returns an extended character of 164 when
  840. pressed while Alt is down.
  841. - FuncKey. Defined in Note 2.
  842. - SpecCtlKey. The Alt+ values of the Escape, Backspace, and Enter keys
  843. are extended characters equaling 1, 14, and 28 (decimal), respectively.
  844. When AltGraphics is used, the Char3 value is returned if it is nonzero and if
  845. an AltGraf bit is set in XTableFlags1. Otherwise, it is treated the same as
  846. the Alt key.
  847. * Note 8
  848. Accent Key. When an accent key is pressed with Ctrl or Alt, it is treated as
  849. a regular key. The character it translates to is the one in the CtlAccent or
  850. AltAccent field of the AccentEntry pointed to by the Char5 value of the
  851. KeyDef. If the key being defined has no defined value with Ctrl or Alt, it
  852. should have zeros in the field of the undefined combination.
  853. When an accent key is pressed by itself (or with Right Shift, Left Shift, or
  854. AltGraphics), it is not translated immediately. The Char1 (or Char2, when
  855. Left or Right Shift or AltGraphics is used) index in the KeyDef record is
  856. used with the next key received to check if the next key has an accent
  857. mapping. If that next key has no mapping for this accent (that is, if it has
  858. no bit set in its AccentFlags), or if that next key is not found in this
  859. accent's AccentEntry, then the character value in the NonAccent field of the
  860. AccentEntry is used as the character to display. It is followed by the
  861. translation of that next key after the not-an-accent beep is sounded.
  862. Notice that if a key doesn't change when a Left or Right Shift key is
  863. pressed, it should use the same value for Char1 and Char2 so the accent
  864. applies in both the shifted and nonshifted cases. If the accent value is
  865. undefined when used with a shift key or AltGraphics, the value in Char2 or
  866. Char3 should be 0.
  867. Any accent key that doesn't have an Alt or Ctrl mapping should put zeros in
  868. the AltAccent and CtlAccent fields of its AccentEntry. If the value in the
  869. table is between 1 and 7, then the key is considered an accent key and
  870. further accent key processing is indicated. See Note 1 for more information.
  871. * Note 9
  872. Extended State Key. For special Country support, the keyboard device
  873. driver maintains another byte of shift status. Key types 12h and 13h are
  874. provided for manipulation of that byte. The other fields of the KeyDef are:
  875. - Char1. A mask in which bits that are on define the field being used for
  876. the Char2 value. Only bits in the NLS shift status byte that correspond
  877. to the bits in this byte are altered by the Char2 value.
  878. - Char2. For KeyType 12h (Extended Shift), the value to OR into the
  879. byte when the make code is seen. Also, the inverted value is ANDed
  880. when the break code is seen. For KeyType 13h (Extended Toggle), the
  881. value XORed into the byte on each make code seen (break code
  882. ignored).
  883. - Char3. Use in place of the Char2 when the secondary key prefix (hex
  884. E0) is seen immediately prior to this key.
  885. For example, Char1 or Char2 can define single shift status bits to
  886. set/clear/toggle. Char2 can be a set of coded bits, delineated by Char1, that
  887. are set to a numeric value when the key is pressed and cleared to zero
  888. when released (or on the next press, if toggled). The whole byte can be
  889. set to Char2 when Char1 has all bits on.
  890. * Note 10
  891. Space Key. The key treated as the space character should have a flag set
  892. in its AccentFlags field for each possible accent (that is, for each defined
  893. AccentEntry in the AccentTable). And each AccentEntry should have the
  894. Space character defined as one of its accented characters, with the
  895. translation having the same value as the accent character itself. The reason
  896. for this is that, by definition, an Accent Key followed by the space
  897. character maps to the accent character alone. If the table is not set up as
  898. just described, a not-an-accent beep is sounded whenever the accent key
  899. followed by a space is pressed.
  900. Notice that the space key is defined as a SpecKeyA (type 4) because its
  901. use, in conjunction with the Alt key, is allowed. In this case, and when
  902. used with the Ctrl key, it returns the ASCII space character. This works
  903. correctly, except in the case of the diaresis accent (double-dot) in code
  904. page 437. The space is treated as an invalid character and the beep result
  905. occurs, with the diaresis represented by double quotation marks. The
  906. characters displayed depend upon the language in effect when the invalid
  907. diaresis is encountered. For some languages, the character substituted is
  908. the double-quotation marks; for others, the character used is the F9h
  909. character.
  910. * Note 11
  911. KbdType identifies the hardware-specific keyboard used by this table. The
  912. values and allowable types are the same as those specified in IOCTL call
  913. KBD_GETKEYBDTYPE (1 means extended keyboard, which is used for all common
  914. keyboard types).
  915. * Note 12
  916. The DefaultTable flag in XtableFlags1 is used by the KEYB utility in loading
  917. code pages when changing from one language to another. It identifies the
  918. default code page to KEYB, should KEYB not find one or both CODEPAGE=
  919. defined code pages.
  920. * Note 13
  921. The Language IDs and Subcountry IDs used are as follows:
  922. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  923. ³Keyboard Layout ³Keyboard Layout ³Country ³
  924. ³Country Code ³SubCountry Code ³ ³
  925. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  926. ³ AR ³ 785 ³Arabic-speaking ³
  927. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  928. ³ BE ³ 120 ³Belgium ³
  929. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  930. ³ CF ³ 058 ³Canadian-French ³
  931. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  932. ³ CS ³ 243 ³Czech Republic ³
  933. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  934. ³ CS ³ 245 ³Czech Republic ³
  935. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  936. ³ DK ³ 159 ³Denmark ³
  937. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  938. ³ SU ³ 153 ³Finland ³
  939. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  940. ³ FR ³ 120 ³France ³
  941. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  942. ³ FR ³ 189 ³France ³
  943. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  944. ³ GR ³ 129 ³Germany ³
  945. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  946. ³ HE ³ 972 ³Hebrew-speaking ³
  947. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  948. ³ HU ³ 208 ³Hungary ³
  949. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  950. ³ IS ³ 197 ³Iceland ³
  951. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  952. ³ IT ³ 141 ³Italy ³
  953. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  954. ³ IT ³ 142 ³Italy ³
  955. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  956. ³ LA ³ 171 ³Latin-American ³
  957. ³ ³ ³Spanish ³
  958. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  959. ³ NL ³ 143 ³Netherlands ³
  960. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  961. ³ NO ³ 155 ³Norway ³
  962. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  963. ³ PL ³ 214 ³Poland ³
  964. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  965. ³ PO ³ 163 ³Portugal ³
  966. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  967. ³ SP ³ 172 ³Spain ³
  968. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  969. ³ SV ³ 153 ³Sweden ³
  970. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  971. ³ SF ³ 150F ³Swiss-French ³
  972. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  973. ³ SG ³ 150G ³Swiss-German ³
  974. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  975. ³ TR ³ 179 ³Turkey ³
  976. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  977. ³ UK ³ 166 ³United Kingdom ³
  978. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  979. ³ UK ³ 168 ³United Kingdom ³
  980. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  981. ³ US ³ 103 ³United States ³
  982. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  983. ³ YU ³ 234 ³Former Yugoslavia ³
  984. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  985. * Note 14
  986. Keytype 15. When the Alt or Alt+Shift keys are pressed, both XlatedChar
  987. and XlatedScan in the CharData record will have the same value.
  988. * Note 15
  989. If the Charx value is in the range of 1-7, then Charx identifies an accent
  990. key. Otherwise, Charx is treated as a valid ASCII character. This does not
  991. apply to Ctrl+Charx sequences.
  992. Note 16
  993. If Alt+Gr, Alt+Shift, or Alt+Ctrl are pressed, and Char3 is 0, the Alt key is
  994. used to translate to a valid result.
  995. Note 17
  996. The * key on the keypad of the Enhanced keyboard, although producing the
  997. same scan code/character as that of the IBM Personal Computer AT*
  998. keyboard, is treated differently because a dedicated Print Screen key exists
  999. on the Enhanced keyboard. The following scan codes/characters are
  1000. returned by the physical keyboard device driver for the Enhanced keyboard
  1001. * key on the keypad:
  1002. Unshifted 37H/2AH
  1003. Shifted 37H/2AH
  1004. Ctrl 96H/00
  1005. Alt 37H/00
  1006. * Note 18
  1007. Size. The code page described here has the following dimensions:
  1008. Xlate Header = 40
  1009. 127 KeyDefs @ 7 bytes = 889
  1010. 7 AccentEntries @ 46 bytes = 322
  1011. ----
  1012. 1251 bytes
  1013. If more than 6 AccentEntries are needed, then the following format is used:
  1014. In the first 6 AccentEntries, the length is set at 20, with unused elements
  1015. set to zero. For each AccentEntry of 7 and greater, up to 120 element pairs
  1016. may exist, and the length is dynamic.
  1017. For each AccentEntry of 7 and greater, the first byte in the record will
  1018. contain the LENGTH of the AccentEntry record. The LENGTH value is defined
  1019. as the total length in bytes of the AccentEntry record including the LENGTH
  1020. byte.
  1021. The record is defined as follows:
  1022. AccEnt <l,a,b,c,d,e,f,c1,s1,c2,s2..c120,s120>
  1023. where....
  1024. l is the total length in bytes of the AccEnt including itself.
  1025. a &b are the scan code &char to use when the key following this accent
  1026. is not affected by the accent so the accent itself must be used.
  1027. c &d are the scan code &char to use when Ctl+[accent] is pressed.
  1028. e &f do the same for Alt+[accent].
  1029. c1,s1 - c120,s120 are the char/scan code mapping for accented translation.
  1030. Adding more than 7 accents will make the standard 1251-byte table an
  1031. extended variable size.
  1032. }
  1033. {Register a keyboard subsystem within a session.}
  1034. {ModuleName - dynamic link module name, maximum length is 8 bytes, ProcName is
  1035. a dynamic link entry point name of a routine that receives control when any of
  1036. the registered functions are called. Maximum length is 32 bytes, FnMask - see
  1037. KR_* constants}
  1038. {Possible return codes:
  1039. 0 NO_ERROR
  1040. 408 ERROR_KBD_INVALID_ASCIIZ
  1041. 409 ERROR_KBD_INVALID_MASK
  1042. 410 ERROR_KBD_REGISTER
  1043. 464 ERROR_KBD_DETACHED
  1044. 504 ERROR_KBD_EXTENDED_SG}
  1045. {Remarks:
  1046. * There can be only one KbdRegister call outstanding for each session without
  1047. an intervening KbdDeRegister. KbdDeRegister must be issued by the same
  1048. process that issued the KbdRegister.}
  1049. function KbdRegister(ModuleName,ProcName:PChar;FnMask:cardinal):word;
  1050. function KbdRegister(ModuleName,ProcName:string;FnMask:cardinal):word;
  1051. {Deregister a keyboard subsystem previously registered within a session - only
  1052. the process that issued the KbdRegister may issue KbdDeRegister.}
  1053. {Possible return codes:
  1054. 0 NO_ERROR
  1055. 411 ERROR_KBD_DEREGISTER
  1056. 464 ERROR_KBD_DETACHED
  1057. 504 ERROR_KBD_EXTENDED_SG}
  1058. function KbdDeRegister:word;
  1059. {Return a character data record from the keyboard.}
  1060. {Key - see TKbdKeyInfo record type, WaitFlag - see IO_WAIT and IO_NOWAIT
  1061. constants, KbdHandle is the default keyboard (0) or a logical keyboard.}
  1062. {Possible return codes are:
  1063. 0 NO_ERROR
  1064. 375 ERROR_KBD_INVALID_IOWAIT
  1065. 439 ERROR_KBD_INVALID_HANDLE
  1066. 445 ERROR_KBD_FOCUS_REQUIRED
  1067. 447 ERROR_KBD_KEYBOARD_BUSY
  1068. 464 ERROR_KBD_DETACHED
  1069. 504 ERROR_KBD_EXTENDED_SG}
  1070. {Remarks:
  1071. * On an enhanced keyboard, the secondary enter key returns the normal
  1072. character 0DH and a scan code of E0H.
  1073. * Double-byte character codes (DBCS) require two function calls to obtain the
  1074. entire code.
  1075. * If shift report is set with KbdSetStatus, the CharData record returned
  1076. reflects changed shift information only.
  1077. * Extended ASCII codes are identified with the status byte, bit 1 on and the
  1078. ASCII character code being either 00H or E0H. Both conditions must be
  1079. satisfied for the character to be an extended keystroke. For extended
  1080. ASCII codes, the scan code byte returned is the second code (extended
  1081. code). Usually the extended ASCII code is the scan code of the primary key
  1082. that was pressed.
  1083. * A thread in the foreground session that repeatedly polls the keyboard with
  1084. KbdCharIn (with no wait), can prevent all regular priority class threads
  1085. from executing. If polling must be used and a minimal amount of other
  1086. processing is being performed, the thread should periodically yield to the
  1087. CPU by issuing a DosSleep call for an interval of at least 5 milliseconds.}
  1088. function KbdCharIn(var Key:TKbdKeyInfo;WaitFlag,KbdHandle:word):word;
  1089. {Return any available character data record from the keyboard
  1090. without removing it from the buffer.}
  1091. {Key - see TKbdKeyInfo record type, KbdHandle is the default keyboard (0)
  1092. or a logical keyboard.}
  1093. {Possible return codes are:
  1094. 0 NO_ERROR
  1095. 439 ERROR_KBD_INVALID_HANDLE
  1096. 445 ERROR_KBD_FOCUS_REQUIRED
  1097. 447 ERROR_KBD_KEYBOARD_BUSY
  1098. 464 ERROR_KBD_DETACHED
  1099. 504 ERROR_KBD_EXTENDED_SG}
  1100. {Remarks:
  1101. * On an enhanced keyboard, the secondary enter key returns the normal
  1102. character 0DH and a scan code of E0H.
  1103. * Double-byte character codes (DBCS) require two function calls to obtain the
  1104. entire code.
  1105. * If shift report is set with KbdSetStatus the CharData record returned,
  1106. reflects changed shift information only.
  1107. * Extended ASCII codes are identified with the status byte, bit 1 on and the
  1108. ASCII character code being either 00H or E0H. Both conditions must be
  1109. satisfied for the character to be an extended keystroke. For extended
  1110. ASCII codes, the scan code byte returned is the second code (extended
  1111. code). Usually the extended ASCII code is the scan code of the primary key
  1112. that was pressed.
  1113. * A thread in the foreground session that repeatedly polls the keyboard with
  1114. KbdCharIn (with no wait), can prevent all regular priority class threads
  1115. from executing. If polling must be used and a minimal amount of other
  1116. processing is being performed, the thread should periodically yield the CPU
  1117. by issuing a DosSleep call for an interval of at least 5 milliseconds.}
  1118. function KbdPeek(var Key:TKbdKeyInfo;KbdHandle:word):word;
  1119. {Read a character string (character codes only) from the keyboard.}
  1120. {CharBuf is a buffer for returned characters, LenInOut - see TStringInBuf
  1121. record type, WaitFlag - see IO_WAIT and IO_NOWAIT constants, KbdHandle is the
  1122. default keyboard (0) or a logical keyboard.}
  1123. {Possible return codes are:
  1124. 0 NO_ERROR
  1125. 375 ERROR_KBD_INVALID_IOWAIT
  1126. 439 ERROR_KBD_INVALID_HANDLE
  1127. 445 ERROR_KBD_FOCUS_REQUIRED
  1128. 464 ERROR_KBD_DETACHED
  1129. 504 ERROR_KBD_EXTENDED_SG}
  1130. {Remarks:
  1131. * The character strings may be optionally echoed on the display if echo mode
  1132. is set. When echo is on each character is echoed as it is read from the
  1133. keyboard. Echo mode and binary mode are mutually exclusive. Reference
  1134. KbdSetStatus and KbdGetStatus for more information.
  1135. * The default input mode is ASCII. In ASCII mode, 2-byte character codes only
  1136. return in complete form. An extended ASCII code is returned in a 2-byte
  1137. string. The first byte is 0DH or E0H and the next byte is an extended code.
  1138. * In input mode (binary, ASCII), the following returns can be set and
  1139. retrieved with KbdSetStatus and KbdGetStatus:
  1140. Turnaround Character
  1141. Echo Mode
  1142. Interim Character Flag
  1143. Shift State
  1144. * The received input length is also used by the KbdStringIn line edit
  1145. functions for re-displaying and entering a caller specified string. On the
  1146. next KbdStringIn call the received input length indicates the length of the
  1147. input buffer that may be recalled by the user using the line editing keys.
  1148. A value of 0 inhibits the line editing function for the current KbdStringIn
  1149. request.
  1150. * KbdStringIn completes when the handle has access to the physical keyboard
  1151. (focus), or is equal to zero and no other handle has the focus.}
  1152. function KbdStringIn(var CharBuf;var LenInOut:TStringInBuf;WaitFlag:word;
  1153. KbdHandle:word):word;
  1154. {Clear the keystroke buffer.}
  1155. {KbdHandle is the default keyboard (0) or a logical keyboard.}
  1156. {Possible return codes are:
  1157. 0 NO_ERROR
  1158. 439 ERROR_KBD_INVALID_HANDLE
  1159. 445 ERROR_KBD_FOCUS_REQUIRED
  1160. 447 ERROR_KBD_KEYBOARD_BUSY
  1161. 464 ERROR_KBD_DETACHED
  1162. 504 ERROR_KBD_EXTENDED_SG}
  1163. {Remarks:
  1164. * KbdFlushBuffer completes when the handle has access to the physical
  1165. keyboard (focus), or is equal to zero and no other handle has the focus.}
  1166. function KbdFlushBuffer(KbdHandle:word):word;
  1167. {Set the characteristics of the keyboard.}
  1168. {Status - see TKbdInfo record type, KbdHandle is the default keyboard (0) or
  1169. a logical keyboard.}
  1170. {Possible return codes are:
  1171. 0 NO_ERROR
  1172. 376 ERROR_KBD_INVALID_LENGTH
  1173. 377 ERROR_KBD_INVALID_ECHO_MASK
  1174. 378 ERROR_KBD_INVALID_INPUT_MASK
  1175. 439 ERROR_KBD_INVALID_HANDLE
  1176. 445 ERROR_KBD_FOCUS_REQUIRED
  1177. 447 ERROR_KBD_KEYBOARD_BUSY
  1178. 464 ERROR_KBD_DETACHED
  1179. 504 ERROR_KBD_EXTENDED_SG}
  1180. {Remarks:
  1181. * Shift return (bit 8 in sysstate) must be disabled in ASCII mode.
  1182. * KbdSetStatus is ignored for a Vio-windowed application.}
  1183. function KbdSetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  1184. {Get the current state of the keyboard.}
  1185. {Status - see TKbdInfo record type, KbdHandle is the default keyboard (0) or
  1186. a logical keyboard.}
  1187. {Possible return codes:
  1188. 0 NO_ERROR
  1189. 376 ERROR_KBD_INVALID_LENGTH
  1190. 439 ERROR_KBD_INVALID_HANDLE
  1191. 445 ERROR_KBD_FOCUS_REQUIRED
  1192. 447 ERROR_KBD_KEYBOARD_BUSY
  1193. 464 ERROR_KBD_DETACHED
  1194. 504 ERROR_KBD_EXTENDED_SG}
  1195. {Remarks:
  1196. * The initial state of the keyboard is established by the system at
  1197. application load time. Some default states may be modified by the
  1198. application through KbdSetStatus. KbdGetStatus returns only those keyboard
  1199. parameters initially set by KbdSetStatus. The returned parameters are:
  1200. Input Mode, Interim Character Flags, Shift State, Echo State, Turnaround
  1201. Character
  1202. * KbdGetStatus completes only when the handle has access to the physical
  1203. keyboard (focus) or the handle is 0 and no other handle has the focus.}
  1204. function KbdGetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  1205. {Set the code page used to translate key strokes received from the keyboard for
  1206. current process.}
  1207. {Reserved - reserved, must be set to 0, CodePage - code-page ID in the
  1208. application's data area, must be equivalent to one of the code-page IDs
  1209. specified on the CONFIG.SYS CODEPAGE= statement or 0, an error results
  1210. otherwise, KbdHandle is the default keyboard (0) or a logical keyboard.}
  1211. {Possible return codes:
  1212. 0 NO_ERROR
  1213. 439 ERROR_KBD_INVALID_HANDLE
  1214. 445 ERROR_KBD_FOCUS_REQUIRED
  1215. 447 ERROR_KBD_KEYBOARD_BUSY
  1216. 448 ERROR_KBD_INVALID_CODEPAGE
  1217. 464 ERROR_KBD_DETACHED
  1218. 504 ERROR_KBD_EXTENDED_SG}
  1219. {Remarks:
  1220. * Keyboard code page support is not available without the DEVINFO=KBD
  1221. statement in the CONFIG.SYS file.}
  1222. function KbdSetCp(Reserved,CodePage,KbdHandle:word):word;
  1223. {Query the code page being used to translate scan codes to ASCII characters.}
  1224. {Reserved must be set to 0. The keyboard support returns the current code
  1225. page for a specified keyboard handle in CodePage, it is one of the code page
  1226. IDs specified in the CONFIG.SYS CODEPAGE= statement or 0000. KbdHandle is
  1227. the default keyboard (0) or a logical keyboard.}
  1228. {Possible return codes:
  1229. 0 NO_ERROR
  1230. 373 ERROR_KBD_PARAMETER
  1231. 439 ERROR_KBD_INVALID_HANDLE
  1232. 445 ERROR_KBD_FOCUS_REQUIRED
  1233. 447 ERROR_KBD_KEYBOARD_BUSY
  1234. 464 ERROR_KBD_DETACHED
  1235. 504 ERROR_KBD_EXTENDED_SG}
  1236. {Remarks:
  1237. * CodePage is set to the currently active keyboard code page. A value of 0
  1238. indicates the code page translation table in use is the ROM code page
  1239. translation table provided by the hardware.}
  1240. function KbdGetCp(Reserved:cardinal;var CodePage:word;KbdHandle:word):word;
  1241. {Create a new logical keyboard.}
  1242. {Handle for the new logical keyboard returned in KbdHandle.}
  1243. {Possible return codes:
  1244. 0 NO_ERROR
  1245. 440 ERROR_KBD_NO_MORE_HANDLE
  1246. 441 ERROR_KBD_CANNOT_CREATE_KCB
  1247. 464 ERROR_KBD_DETACHED
  1248. 504 ERROR_KBD_EXTENDED_SG}
  1249. {Remarks:
  1250. * KbdOpen blocks while another thread has the keyboard focus (by way of
  1251. KbdGetFocus) until the thread with the focus issues KbdFreeFocus.
  1252. Therefore, to prevent KbdOpen from blocking, it is recommended that KbdOpen
  1253. be issued only while the current thread has the focus. For example:
  1254. KbdGetFocus wait until focus available on handle 0
  1255. KbdOpen get a logical keyboard handle
  1256. KbdFreeFocus give up the focus on handle 0}
  1257. function KbdOpen(var KbdHandle:word):word;
  1258. {Close the existing logical keyboard identified by the keyboard handle}
  1259. {KbdHandle is the default keyboard (0) or a logical keyboard}
  1260. {Possible return codes:
  1261. 0 NO_ERROR
  1262. 439 ERROR_KBD_INVALID_HANDLE
  1263. 464 ERROR_KBD_DETACHED
  1264. 504 ERROR_KBD_EXTENDED_SG}
  1265. {Remarks:
  1266. * KbdClose blocks while another thread has the keyboard focus (by way of
  1267. KbdGetFocus) until the thread with the focus issues KbdFreeFocus.
  1268. Therefore, to prevent KbdClose from blocking, it is recommended that
  1269. KbdClose be issued only while the current thread has the focus. For
  1270. example:
  1271. KbdGetFocus wait until focus available on handle 0
  1272. KbdClose close a logical keyboard handle
  1273. KbdFreeFocus give up the focus on handle 0}
  1274. function KbdClose(KbdHandle:word):word;
  1275. {Bind the logical keyboard to the physical keyboard.}
  1276. {KbdHandle is the default keyboard (0) or a logical keyboard}
  1277. {Possible return codes:
  1278. 0 NO_ERROR
  1279. 439 ERROR_KBD_INVALID_HANDLE
  1280. 445 ERROR_KBD_FOCUS_REQUIRED
  1281. 464 ERROR_KBD_DETACHED
  1282. 504 ERROR_KBD_EXTENDED_SG}
  1283. function KbdGetFocus(WaitFlag,KbdHandle:word):word;
  1284. {Free the logical-to-physical keyboard bond created by KbdGetFocus.}
  1285. {KbdHandle is the default keyboard (0) or a logical keyboard}
  1286. {Possible return codes:
  1287. 0 NO_ERROR
  1288. 439 ERROR_KBD_INVALID_HANDLE
  1289. 445 ERROR_KBD_FOCUS_REQUIRED
  1290. 464 ERROR_KBD_DETACHED
  1291. 504 ERROR_KBD_EXTENDED_SG}
  1292. {Remarks:
  1293. * KbdFreeFocus may be replaced by issuing KbdRegister. Unlike other keyboard
  1294. subsystem functions, the replaced KbdFreeFocus is called only if there is
  1295. an outstanding focus.}
  1296. function KbdFreeFocus(KbdHandle:word):word;
  1297. {Synchronize access from a keyboard subsystem to the keyboard device driver.}
  1298. {WaitFlag - see IO_WAIT and IO_NOWAIT constants (wait / don't wait for access
  1299. to the device driver.}
  1300. {Possible return codes:
  1301. 0 NO_ERROR
  1302. 121 ERROR_SEM_TIMEOUT}
  1303. {Remarks:
  1304. * KbdSynch blocks all other threads within a session until return from the
  1305. subsystem to the router. To ensure proper synchronization, KbdSynch should
  1306. be issued by a keyboard subsystem if it intends to issue a DosDevIOCtl or
  1307. access dynamically shared data. KbdSynch does not protect globally shared
  1308. data from threads in other sessions.}
  1309. function KbdSynch (WaitFlag:word):word;
  1310. {Raise the priority of the foreground keyboard's thread.}
  1311. {Possible return codes:
  1312. 0 NO_ERROR
  1313. 447 ERROR_KBD_KEYBOARD_BUSY
  1314. 504 ERROR_KBD_EXTENDED_SG}
  1315. {Remarks:
  1316. * KbdSetFgnd marks the current process that owns the keyboard. Threads in
  1317. this process receive a priority boost. The previous foreground keyboard
  1318. threads lose their priority boost.
  1319. * This function should only be issued by a Keyboard Subsystem during
  1320. KbdCharIn or KbdStringIn processing.}
  1321. function KbdSetFgnd:word;
  1322. {Return the attached keyboard's hardware-generated identification value.}
  1323. {HWID is a pointer to the caller's data area, see TKbdHWID, KbdHandle is the
  1324. default keyboard (0) or a logical keyboard.}
  1325. {Possible return codes:
  1326. 0 NO_ERROR
  1327. 373 ERROR_KBD_PARAMETER
  1328. 447 ERROR_KBD_KEYBOARD_BUSY
  1329. 464 ERROR_KBD_DETACHED
  1330. 504 ERROR_KBD_EXTENDED_SG}
  1331. {Remarks:
  1332. * In past OS/2 releases, all keyboards could be supported by knowing the
  1333. hardware family information available with keyboard IOCTL 77H. However,
  1334. with the addition of the 122-key keyboard, recognition was not containable
  1335. by hardware family information alone. The 122-key keyboard has a number of
  1336. differences from other keyboards. Therefore, applications performing
  1337. keystroke specific functions may need to determine specifically which
  1338. keyboard is attached.
  1339. * This function is of particular usefulness for applications providing Custom
  1340. Translate Tables and mapping keyboard layouts.}
  1341. function KbdGetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  1342. {Undocumented in official IBM documentation}
  1343. function KbdSetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  1344. {Translate scan codes with shift states into ASCII codes.}
  1345. {TransData - see TKbdTransData, KbdHandle is the default keyboard (0) or a
  1346. logical keyboard.}
  1347. {Possible return codes:
  1348. 0 NO_ERROR
  1349. 439 ERROR_KBD_INVALID_HANDLE
  1350. 445 ERROR_KBD_FOCUS_REQUIRED
  1351. 447 ERROR_KBD_KEYBOARD_BUSY
  1352. 464 ERROR_KBD_DETACHED
  1353. 504 ERROR_KBD_EXTENDED_SG}
  1354. {Remarks:
  1355. * It may take several calls to complete a translation because of accent key
  1356. combinations, or other complex operations.
  1357. * The fsShift and sZero are for use by the keyboard translation routines.
  1358. These fields are reserved and must only be accessed by the caller prior
  1359. to starting a translation sequence and then they must be set to zero.
  1360. The KbdXlate function is intended to be used for translating a particular
  1361. scan code for a given shift state. The KbdXlate function is not intended
  1362. to be a replacement for the OS/2 system keystroke translation function.}
  1363. function KbdXlate(var TransData:TKbdTrans;KbdHandle:word):word;
  1364. {Install, on the specified handle, the translate table which this call points
  1365. to. This translate table affects only this handle.}
  1366. {XLateTbl is the translation table used to translate scan code to ASCII code
  1367. for a specified handle, KbdHandle is the default keyboard (0) or a logical
  1368. keyboard.}
  1369. {Possible return codes:
  1370. 0 NO_ERROR
  1371. 377 ERROR_KBD_INVALID_ECHO_MASK
  1372. 378 ERROR_KBD_INVALID_INPUT_MASK
  1373. 439 ERROR_KBD_INVALID_HANDLE
  1374. 445 ERROR_KBD_FOCUS_REQUIRED
  1375. 447 ERROR_KBD_KEYBOARD_BUSY
  1376. 464 ERROR_KBD_DETACHED
  1377. 504 ERROR_KBD_EXTENDED_SG}
  1378. {Remarks:
  1379. * The translate table must be maintained in the caller's memory. No copy of
  1380. the translate table is made by KbdSetCustXt.
  1381. * KbdSetCp reverses the action of KbdSetCustXt and sets the handle equal to
  1382. one of the system translate tables. If memory is dynamically allocated by
  1383. the caller for the translate table and is freed before the KbdSetCp is
  1384. performed, KbdSetCp and future translations may fail.}
  1385. function KbdSetCustXt(var XLateTbl:TXLateTbl;KbdHandle:word):word;
  1386. (* Following routines are not supported
  1387. (just have a look in some C header
  1388. file - you probably won't find it there either).
  1389. KbdInit (index 2)
  1390. KbdLoadInstance (index 6)
  1391. KbdSwitchFgnd (index 15)
  1392. KbdShellInit (index 16)
  1393. KbdFree (index 19)
  1394. *)
  1395. {***************************************************************************}
  1396. implementation
  1397. {***************************************************************************}
  1398. function KbdRegister(ModuleName,ProcName:PChar;FnMask:cardinal):word;
  1399. external 'EMXWRAP' index 208;
  1400. {external 'KBDCALLS' index 8;}
  1401. function KbdRegister(ModuleName,ProcName:string;FnMask:cardinal):word;
  1402. begin
  1403. if byte(ModuleName[0])>8 then byte(ModuleName[0]):=8;
  1404. ModuleName[Succ(byte(ModuleName[0]))]:=#0;
  1405. if byte(ProcName[0])>32 then byte(ProcName[0]):=32;
  1406. ProcName[Succ(byte(ProcName[0]))]:=#0;
  1407. KbdRegister:=KbdRegister(@ModuleName[1],@ProcName[1],FnMask);
  1408. end;
  1409. function KbdDeRegister:word;
  1410. external 'EMXWRAP' index 220;
  1411. {external 'KBDCALLS' index 20;}
  1412. function KbdCharIn(var Key:TKbdKeyInfo;WaitFlag,KbdHandle:word):word;
  1413. external 'EMXWRAP' index 204;
  1414. {external 'KBDCALLS' index 4;}
  1415. function KbdPeek(var Key:TKbdKeyInfo;KbdHandle:word):word;
  1416. external 'EMXWRAP' index 222;
  1417. {external 'KBDCALLS' index 22;}
  1418. function KbdStringIn(var CharBuf;var LenInOut:TStringInBuf;WaitFlag:word;
  1419. KbdHandle:word):word;
  1420. external 'EMXWRAP' index 209;
  1421. {external 'KBDCALLS' index 9;}
  1422. function KbdFlushBuffer(KbdHandle:word):word;
  1423. external 'EMXWRAP' index 213;
  1424. {external 'KBDCALLS' index 13;}
  1425. function KbdSetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  1426. external 'EMXWRAP' index 211;
  1427. {external 'KBDCALLS' index 11;}
  1428. function KbdGetStatus(var Status:TKbdInfo;KbdHandle:word):word;
  1429. external 'EMXWRAP' index 210;
  1430. {external 'KBDCALLS' index 10;}
  1431. function KbdSetCp(Reserved,CodePage,KbdHandle:word):word;
  1432. external 'EMXWRAP' index 205;
  1433. {external 'KBDCALLS' index 5;}
  1434. function KbdGetCp(Reserved:cardinal;var CodePage:word;KbdHandle:word):word;
  1435. external 'EMXWRAP' index 203;
  1436. {external 'KBDCALLS' index 3;}
  1437. function KbdOpen(var KbdHandle:word):word;
  1438. external 'EMXWRAP' index 223;
  1439. {external 'KBDCALLS' index 23;}
  1440. function KbdClose(KbdHandle:word):word;
  1441. external 'EMXWRAP' index 217;
  1442. {external 'KBDCALLS' index 17;}
  1443. function KbdGetFocus(WaitFlag,KbdHandle:word):word;
  1444. external 'EMXWRAP' index 212;
  1445. {external 'KBDCALLS' index 12;}
  1446. function KbdFreeFocus(KbdHandle:word):word;
  1447. external 'EMXWRAP' index 218;
  1448. {external 'KBDCALLS' index 18;}
  1449. function KbdSynch (WaitFlag:word):word;
  1450. external 'EMXWRAP' index 207;
  1451. {external 'KBDCALLS' index 7;}
  1452. function KbdSetFgnd:word;
  1453. external 'EMXWRAP' index 221;
  1454. {external 'KBDCALLS' index 21;}
  1455. function KbdGetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  1456. external 'EMXWRAP' index 224;
  1457. {external 'KBDCALLS' index 24;}
  1458. function KbdSetHWID(var HWID:TKbdHWID;KbdHandle:word):word;
  1459. external 'EMXWRAP' index 225;
  1460. {external 'KBDCALLS' index 25;}
  1461. function KbdXlate(var TransData:TKbdTrans;KbdHandle:word):word;
  1462. external 'EMXWRAP' index 214;
  1463. {external 'KBDCALLS' index 14;}
  1464. function KbdSetCustXt(var XLateTbl:TXLateTbl;KbdHandle:word):word;
  1465. external 'EMXWRAP' index 201;
  1466. {external 'KBDCALLS' index 1;}
  1467. end.
  1468.