keyboard.xml 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. <?xml version="1.0" encoding="ISO8859-1"?>
  2. <fpdoc-descriptions>
  3. <!--
  4. $Id$
  5. This file is part of the FPC documentation.
  6. Copyright (C) 1997, by Michael Van Canneyt
  7. The FPC documentation is free text; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11. The FPC Documentation is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with the FPC documentation; see the file COPYING.LIB. If not,
  17. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. Boston, MA 02111-1307, USA.
  19. -->
  20. <package name="rtl">
  21. <module name="keyboard">
  22. <short>Access to low-level keyboard functions</short>
  23. <!-- \FPCexampledir{kbdex} -->
  24. <descr>
  25. <p>
  26. The <file>KeyBoard</file> unit implements a keyboard access layer which is system
  27. independent. It can be used to poll the keyboard state and wait for certain
  28. events. Waiting for a keyboard event can be done with the <link id="GetKeyEvent"/>
  29. function, which will return a driver-dependent key event. This key event can
  30. be translated to a interpretable event by the <link id="TranslateKeyEvent"/>
  31. function. The result of this function can be used in the other event
  32. examining functions.
  33. </p>
  34. <p>
  35. A custom keyboard driver can be installed using the <link id="SetKeyboardDriver"/>
  36. function. The current keyboard driver can be retrieved using the
  37. <link id="GetKeyboardDriver"/> function. The last section of this chapter
  38. demonstrates how to make a keyboard driver.
  39. </p>
  40. </descr>
  41. <element name="errKbdBase">
  42. <short>Base of keyboard routine error reporting constants.</short>
  43. </element>
  44. <element name="errKbdInitError">
  45. <short>Failed to initialize keyboard driver</short>
  46. </element>
  47. <element name="errKbdNotImplemented">
  48. <short>Keyboard driver not implemented.</short>
  49. </element>
  50. <element name="kbdApps">
  51. <short>Application key (popup-menu) pressed.</short>
  52. </element>
  53. <element name="kbdLWin">
  54. <short>Left windows key pressed.</short>
  55. </element>
  56. <element name="kbdRWin">
  57. <short>Right windows key pressed.</short>
  58. </element>
  59. <element name="kbdF1">
  60. <short>F1 function key pressed.</short>
  61. </element>
  62. <element name="kbdF2">
  63. <short>F2 function key pressed.</short>
  64. </element>
  65. <element name="kbdF3">
  66. <short>F3 function key pressed.</short>
  67. </element>
  68. <element name="kbdF4">
  69. <short>F4 function key pressed.</short>
  70. </element>
  71. <element name="kbdF5">
  72. <short>F5 function key pressed.</short>
  73. </element>
  74. <element name="kbdF6">
  75. <short>F6 function key pressed.</short>
  76. </element>
  77. <element name="kbdF7">
  78. <short>F7 function key pressed.</short>
  79. </element>
  80. <element name="kbdF8">
  81. <short>F8 function key pressed.</short>
  82. </element>
  83. <element name="kbdF9">
  84. <short>F9 function key pressed.</short>
  85. </element>
  86. <element name="kbdF10">
  87. <short>F10 function key pressed.</short>
  88. </element>
  89. <element name="kbdF11">
  90. <short>F12 function key pressed.</short>
  91. </element>
  92. <element name="kbdF12">
  93. <short>F12 function key pressed.</short>
  94. </element>
  95. <element name="kbdF13">
  96. <short>F13 function key pressed.</short>
  97. </element>
  98. <element name="kbdF14">
  99. <short>F14 function key pressed.</short>
  100. </element>
  101. <element name="kbdF15">
  102. <short>F15 function key pressed.</short>
  103. </element>
  104. <element name="kbdF16">
  105. <short>F16 function key pressed.</short>
  106. </element>
  107. <element name="kbdF17">
  108. <short>F17 function key pressed.</short>
  109. </element>
  110. <element name="kbdF18">
  111. <short>F18 function key pressed.</short>
  112. </element>
  113. <element name="kbdF19">
  114. <short>F19 function key pressed.</short>
  115. </element>
  116. <element name="kbdF20">
  117. <short>F20 function key pressed.</short>
  118. </element>
  119. <element name="kbFnKey">
  120. <short>function key pressed.</short>
  121. </element>
  122. <element name="ShiftPrefix">
  123. <short>Shift key name index.</short>
  124. </element>
  125. <element name="AltPrefix">
  126. <short>Alt key name index.</short>
  127. </element>
  128. <element name="CtrlPrefix">
  129. <short>Alt key name index.</short>
  130. </element>
  131. <element name="ShiftPrefix">
  132. <short>Shift key name index.</short>
  133. </element>
  134. <element name="kbdHome">
  135. <short>Home key pressed</short>
  136. </element>
  137. <element name="kbdUp">
  138. <short>Arrow up key pressed</short>
  139. </element>
  140. <element name="kbdDown">
  141. <short>Arrow down key pressed</short>
  142. </element>
  143. <element name="kbdPgUp">
  144. <short>Page Up key pressed</short>
  145. </element>
  146. <element name="kbdLeft">
  147. <short>Arrow left key pressed</short>
  148. </element>
  149. <element name="kbdMiddle">
  150. <short>Middle key pad key pressed (numerical 5)</short>
  151. </element>
  152. <element name="kbdRight">
  153. <short>Arrow right key pressed</short>
  154. </element>
  155. <element name="kbdEnd">
  156. <short>End key pressed</short>
  157. </element>
  158. <element name="kbdPgDn">
  159. <short>Page down key pressed</short>
  160. </element>
  161. <element name="kbdInsert">
  162. <short>Insert key pressed</short>
  163. </element>
  164. <element name="kbdDelete">
  165. <short>Delete key pressed</short>
  166. </element>
  167. <element name="kbASCII">
  168. <short>Ascii code key event</short>
  169. </element>
  170. <element name="kbUniCode">
  171. <short>Unicode code key event</short>
  172. </element>
  173. <element name="kbPhys">
  174. <short>Physical key code event</short>
  175. </element>
  176. <element name="kbReleased">
  177. <short>Key release event</short>
  178. </element>
  179. <element name="kbLeftShift">
  180. <short>Left shift key modifier</short>
  181. </element>
  182. <element name="kbRightShift">
  183. <short>Right shift key modifier</short>
  184. </element>
  185. <element name="kbShift">
  186. <short>Shift key modifier</short>
  187. </element>
  188. <element name="kbCtrl">
  189. <short>Control key modifier</short>
  190. </element>
  191. <element name="kbAlt">
  192. <short>Alt key modifier</short>
  193. </element>
  194. <element name="SShift">
  195. <short>Names of modifier keys</short>
  196. <descr>
  197. This constant describes the various modifier keys.
  198. This constant is used by the key event description routines.
  199. It can be changed to localize the key descriptions when needed.
  200. </descr>
  201. <seealso>
  202. <link id="KeyEventToString"/>
  203. <link id="FunctionKeyName"/>
  204. </seealso>
  205. </element>
  206. <element name="SLeftRight">
  207. <short>Names for left-right keys</short>
  208. <descr>
  209. This constant contains strings to describe left and right keys.
  210. This constant is used by the key event description routines.
  211. It can be changed to localize the key descriptions when needed.
  212. </descr>
  213. <seealso>
  214. <link id="KeyEventToString"/>
  215. <link id="FunctionKeyName"/>
  216. </seealso>
  217. </element>
  218. <element name="SUnicodeChar">
  219. <short>Unicode character string.</short>
  220. <descr>
  221. This constant contains a string to denote a unicode key event.
  222. This constant is used by the key event description routines.
  223. It can be changed to localize the key descriptions when needed.
  224. </descr>
  225. <seealso>
  226. <link id="KeyEventToString"/>
  227. <link id="FunctionKeyName"/>
  228. </seealso>
  229. </element>
  230. <element name="SScanCode">
  231. <short>Scancode key</short>
  232. <descr>
  233. This constant contains a string to denote a scancode key event.
  234. This constant is used by the key event description routines.
  235. It can be changed to localize the key descriptions when needed.
  236. </descr>
  237. <seealso>
  238. <link id="KeyEventToString"/>
  239. <link id="FunctionKeyName"/>
  240. </seealso>
  241. </element>
  242. <element name="SUnknownFunctionKey">
  243. <short>Unknown function key</short>
  244. <descr>
  245. This constant contains a string to denote that an unknown function key was
  246. found. This constant is used by the key event description routines.
  247. It can be changed to localize the key descriptions when needed.
  248. </descr>
  249. <seealso>
  250. <link id="KeyEventToString"/>
  251. <link id="FunctionKeyName"/>
  252. </seealso>
  253. </element>
  254. <element name="SAnd">
  255. <short>'And' description string</short>
  256. <descr>
  257. This constant is used as the 'And' word in key descriptions.
  258. This constant is used by the key event description routines.
  259. It can be changed to localize the key descriptions when needed.
  260. </descr>
  261. <seealso>
  262. <link id="KeyEventToString"/>
  263. <link id="FunctionKeyName"/>
  264. </seealso>
  265. </element>
  266. <element name="SKeyPad">
  267. <short>Names of keypad keys</short>
  268. <descr>
  269. This constant describes all keypad keys.
  270. This constant is used by the key event description routines.
  271. It can be changed to localize the key descriptions when needed.
  272. </descr>
  273. <seealso>
  274. <link id="KeyEventToString"/>
  275. <link id="FunctionKeyName"/>
  276. </seealso>
  277. </element>
  278. <element name="TKeyEvent">
  279. <short>Base type to describe all key events.</short>
  280. <descr>
  281. <p>
  282. The <var>TKeyEvent</var> type is the base type for all keyboard events.
  283. </p>
  284. <p>
  285. The key stroke is encoded in the 4 bytes of the <var>TKeyEvent</var> type.
  286. The various fields of the key stroke encoding can be obtained by typecasting
  287. the <var>TKeyEvent</var> type to the <link id="TKeyRecord"/> type.
  288. </p>
  289. </descr>
  290. </element>
  291. <element name="TKeyRecord">
  292. <short>Key event decoding type.</short>
  293. <descr>
  294. <p>
  295. The structure of a <var>TKeyRecord</var> structure is explained in the
  296. following table:
  297. </p>
  298. <table>
  299. <caption>Structure of TKeyRecord</caption>
  300. <th><td>Field</td><td>Meaning</td></th>
  301. <tr><td>KeyCode</td><td>
  302. Depending on <var>flags</var> either the physical representation of a key
  303. (under DOS scancode, ascii code pair), or the translated
  304. ASCII/unicode character.
  305. </td></tr>
  306. <tr>
  307. <td>ShiftState</td>
  308. <td>
  309. Shift-state when this key was pressed (or shortly after)
  310. </td></tr>
  311. <tr><td>Flags</td>
  312. <td>
  313. Determine how to interpret <var>KeyCode</var>
  314. </td></tr>
  315. </table>
  316. <p>
  317. The shift-state can be checked using the various shift-state constants,
  318. and the flags in the last byte can be checked using one of the
  319. kbASCII, kbUniCode, kbFnKey, kbPhys, kbReleased constants.
  320. </p>
  321. <p>
  322. If there are two keys returning the same char-code, there's no way to find
  323. out which one was pressed (Gray+ and Simple+). If it needs to be known which
  324. was pressed, the untranslated keycodes must be used, but these are system
  325. dependent. System dependent constants may be defined to cover those, with
  326. possibily having the same name (but different value).
  327. </p>
  328. </descr>
  329. <seealso>
  330. <link id="kbdscancode"/>
  331. <link id="TKeyEvent"/>
  332. </seealso>
  333. </element>
  334. <element name="TKeyboardDriver">
  335. <short>Keyboard driver structure</short>
  336. <descr>
  337. <p>
  338. The <var>TKeyboardDriver</var> record can be used to install a custom keyboard
  339. driver with the <link id="SetKeyboardDriver"/> function.
  340. </p>
  341. <p>
  342. The various fields correspond to the different functions of the keyboard unit
  343. interface. For more information about this record see <link id="kbddriver"/>
  344. </p>
  345. </descr>
  346. <seealso>
  347. <link id="SetKeyboardDriver"/>
  348. <link id="kbddriver"/>
  349. </seealso>
  350. </element>
  351. <element name="DoneKeyboard">
  352. <short>Deactivate keyboard driver.</short>
  353. <descr>
  354. <p>
  355. <var>DoneKeyboard</var> de-initializes the keyboard interface if the keyboard
  356. driver is active. If the keyboard driver is not active, the function does
  357. nothing.
  358. </p>
  359. <p>
  360. This will cause the keyboard driver to clear up any allocated memory,
  361. or restores the console or terminal the program was running in to its
  362. initial state before the call to <link id="InitKeyBoard"/>. This function should
  363. be called on program exit. Failing to do so may leave the terminal or
  364. console window in an unusable state. Its exact action depends on the
  365. platform on which the program is running.
  366. </p>
  367. <p>
  368. For an example, see most other functions.
  369. </p>
  370. </descr>
  371. <errors>
  372. None.
  373. </errors>
  374. <seealso>
  375. <link id="InitKeyBoard"/>
  376. </seealso>
  377. </element>
  378. <element name="FunctionKeyName">
  379. <short>Return string representation of a function key code.</short>
  380. <descr>
  381. <var>FunctionKeyName</var> returns a string representation of the function key
  382. with code <var>KeyCode</var>. This can be an actual function key, or one of the
  383. cursor movement keys.
  384. </descr>
  385. <errors>
  386. In case <var>KeyCode</var> does not contain a function code, the
  387. <var>SUnknownFunctionKey</var> string is returned, appended with the
  388. <var>KeyCode</var>.
  389. </errors>
  390. <seealso>
  391. <link id="ShiftStateToString"/>
  392. <link id="KeyEventToString"/>
  393. </seealso>
  394. <example file="kbdex/ex8"/>
  395. </element>
  396. <element name="GetKeyboardDriver">
  397. <short>Return the current keyboard driver record.</short>
  398. <descr>
  399. <p>
  400. <var>GetKeyBoardDriver</var> returns in <var>Driver</var> the currently active
  401. keyboard driver. This function can be used to enhance an existing
  402. keyboarddriver.
  403. </p>
  404. <p>
  405. For more information on getting and setting the keyboard driver
  406. <link id="kbddriver"/>.
  407. </p>
  408. </descr>
  409. <errors>
  410. None.
  411. </errors>
  412. <seealso>
  413. <link id="SetKeyboardDriver"/>
  414. </seealso>
  415. </element>
  416. <element name="GetKeyEvent">
  417. <short>Get the next raw key event, wait if needed.</short>
  418. <descr>
  419. <p>
  420. <var>GetKeyEvent</var> returns the last keyevent if one was stored in
  421. <var>PendingKeyEvent</var>, or waits for one if none is available.
  422. A non-blocking version is available in <link id="PollKeyEvent"/>.
  423. </p>
  424. <p>
  425. The returned key is encoded as a <var>TKeyEvent</var> type variable, and
  426. is normally the physical key scan code, (the scan code is driver
  427. dependent) which can be translated with one of the translation
  428. functions <link id="TranslateKeyEvent"/> or <link id="TranslateKeyEventUniCode"/>.
  429. See the types section for a description of how the key is described.
  430. </p>
  431. </descr>
  432. <errors>
  433. If no key became available, 0 is returned.
  434. </errors>
  435. <seealso>
  436. <link id="PutKeyEvent"/>
  437. <link id="PollKeyEvent"/>
  438. <link id="TranslateKeyEvent"/>,
  439. <link id="TranslateKeyEventUniCode"/>
  440. </seealso>
  441. <example file="kbdex/ex1"/>
  442. </element>
  443. <element name="GetKeyEventChar">
  444. <short>Get the character key part of a key event.</short>
  445. <descr>
  446. <p>
  447. <var>GetKeyEventChar</var> returns the charcode part of the given
  448. <var>KeyEvent</var>, if it contains a translated character key
  449. keycode. The charcode is simply the ascii code of the
  450. character key that was pressed.
  451. </p>
  452. <p>
  453. It returns the null character if the key was not a character key, but e.g. a
  454. function key.
  455. </p>
  456. <p>
  457. For an example, see <link id="GetKeyEvent"/>
  458. </p>
  459. </descr>
  460. <errors>
  461. None.
  462. </errors>
  463. <seealso>
  464. <link id="GetKeyEventUniCode"/>,
  465. <link id="GetKeyEventShiftState"/>,
  466. <link id="GetKeyEventFlags"/>,
  467. <link id="GetKeyEventCode"/>,
  468. <link id="GetKeyEvent"/>
  469. </seealso>
  470. </element>
  471. <element name="GetKeyEventCode">
  472. <short>Translate function key part of a key event code.</short>
  473. <descr>
  474. <p>
  475. <var>GetKeyEventCode</var> returns the translated function keycode part of
  476. the given KeyEvent, if it contains a translated function key.
  477. </p>
  478. <p>
  479. If the key pressed was not a function key, the null character is returned.
  480. </p>
  481. </descr>
  482. <errors>
  483. None.
  484. </errors>
  485. <seealso>
  486. <link id="GetKeyEventUniCode"/>,
  487. <link id="GetKeyEventShiftState"/>,
  488. <link id="GetKeyEventFlags"/>,
  489. <link id="GetKeyEventChar"/>,
  490. <link id="GetKeyEvent"/>
  491. </seealso>
  492. <example file="kbdex/ex2"/>
  493. </element>
  494. <element name="GetKeyEventFlags">
  495. <short>Extract the flags from a key event.</short>
  496. <descr>
  497. <p>
  498. <var>GetKeyEventFlags</var> returns the flags part of the given
  499. <var>KeyEvent</var>.
  500. </p>
  501. <p>
  502. For an example, see <link id="GetKeyEvent"/>
  503. </p>
  504. </descr>
  505. <errors>
  506. None.
  507. </errors>
  508. <seealso>
  509. <link id="GetKeyEventUniCode"/>,
  510. <link id="GetKeyEventShiftState"/>,
  511. <link id="GetKeyEventCode"/>,
  512. <link id="GetKeyEventChar"/>,
  513. <link id="GetKeyEvent"/>
  514. </seealso>
  515. </element>
  516. <element name="GetKeyEventShiftState">
  517. <short>Return the current state of the shift keys.</short>
  518. <descr>
  519. <p>
  520. <var>GetKeyEventShiftState</var> returns the shift-state values of
  521. the given <var>KeyEvent</var>. This can be used to detect which of the modifier
  522. keys <var>Shift</var>, <var>Alt</var> or <var>Ctrl</var> were pressed. If none were
  523. pressed, zero is returned.
  524. </p>
  525. <p>
  526. Note that this function does not always return expected results;
  527. In a unix X-Term, the modifier keys do not always work.
  528. </p>
  529. </descr>
  530. <errors>
  531. None.
  532. </errors>
  533. <seealso>
  534. <link id="GetKeyEventUniCode"/>,
  535. <link id="GetKeyEventFlags"/>,
  536. <link id="GetKeyEventCode"/>,
  537. <link id="GetKeyEventChar"/>,
  538. <link id="GetKeyEvent"/>
  539. </seealso>
  540. <example file="kbdex/ex3"/>
  541. </element>
  542. <element name="GetKeyEventUniCode">
  543. <short>Return the unicode key event.</short>
  544. <descr>
  545. <var>GetKeyEventUniCode</var> returns the unicode part of the
  546. given <var>KeyEvent</var> if it contains a translated unicode
  547. character.
  548. </descr>
  549. <errors>
  550. None.
  551. </errors>
  552. <seealso>
  553. <link id="GetKeyEventShiftState"/>,
  554. <link id="GetKeyEventFlags"/>,
  555. <link id="GetKeyEventCode"/>,
  556. <link id="GetKeyEventChar"/>,
  557. <link id="GetKeyEvent"/>
  558. </seealso>
  559. </element>
  560. <element name="InitKeyBoard">
  561. <short>Initialize the keyboard driver.</short>
  562. <descr>
  563. <p>
  564. <var>InitKeyboard</var> initializes the keyboard driver.
  565. If the driver is already active, it does nothing. When the driver is
  566. initialized, it will do everything necessary to ensure the functioning of
  567. the keyboard, including allocating memory, initializing the terminal etc.
  568. </p>
  569. <p>
  570. This function should be called once, before using any of the
  571. keyboard functions. When it is called, the <link id="DoneKeyboard"/> function
  572. should also be called before exiting the program or changing the keyboard
  573. driver with <link id="SetKeyboardDriver"/>.
  574. </p>
  575. <p>
  576. For an example, see most other functions.
  577. </p>
  578. </descr>
  579. <errors>
  580. None.
  581. </errors>
  582. <seealso>
  583. <link id="DoneKeyboard"/>
  584. <link id="SetKeyboardDriver"/>
  585. </seealso>
  586. </element>
  587. <element name="AddSequence" skip="1"/>
  588. <element name="FindSequence" skip="1"/>
  589. <element name="RawReadKey" skip="1"/>
  590. <element name="RawReadString" skip="1"/>
  591. <element name="RestoreStartMode" skip="1"/>
  592. <element name="IsFunctionKey">
  593. <short>Check whether a given event is a function key event.</short>
  594. <descr>
  595. <var>IsFunctionKey</var> returns <var>True</var> if the given key event
  596. in <var>KeyEvent</var> was a function key or not.
  597. </descr>
  598. <errors>
  599. None.
  600. </errors>
  601. <seealso>
  602. <link id="GetKeyEvent"/>
  603. </seealso>
  604. <example file="kbdex/ex7"/>
  605. </element>
  606. <element name="KeyEventToString">
  607. <short>Return a string describing the key event.</short>
  608. <descr>
  609. <p>
  610. <var>KeyEventToString</var> translates the key event in <var>KeyEvent</var> to a
  611. human-readable description of the pressed key. It will use the constants
  612. described in the constants section to do so.
  613. </p>
  614. <p>
  615. For an example, see most other functions.
  616. </p>
  617. </descr>
  618. <errors>
  619. If an unknown key is passed, the scancode is returned, prefixed with the
  620. <var>SScanCode</var> string.
  621. </errors>
  622. <seealso>
  623. <link id="FunctionKeyName"/>
  624. <link id="ShiftStateToString"/>
  625. </seealso>
  626. </element>
  627. <element name="KeyPressed">
  628. <short>Check event queue for key press</short>
  629. <descr>
  630. <var>KeyPressed</var> checks the keyboard event queue to see whether a key
  631. event is present, and returns <var>True</var> if a key event is available.
  632. This function simply calls <link id="PollKeyEvent"/> and checks for a valid
  633. result.
  634. </descr>
  635. <errors>
  636. None.
  637. </errors>
  638. <seealso>
  639. <link id="PollKeyEvent"/>
  640. <link id="GetKeyEvent"/>
  641. </seealso>
  642. </element>
  643. <element name="PollKeyEvent">
  644. <short>Get next key event, but does not wait.</short>
  645. <descr>
  646. <p>
  647. <var>PollKeyEvent</var> checks whether a key event is available,
  648. and returns it if one is found. If no event is pending,
  649. it returns 0.
  650. </p>
  651. <p>
  652. Note that this does not remove the key from the pending keys.
  653. The key should still be retrieved from the pending key events
  654. list with the <link id="GetKeyEvent"/> function.
  655. </p>
  656. </descr>
  657. <errors>
  658. None.
  659. </errors>
  660. <seealso>
  661. <link id="PutKeyEvent"/>
  662. <link id="GetKeyEvent"/>
  663. </seealso>
  664. <example file="kbdex/ex4"/>
  665. </element>
  666. <element name="PollShiftStateEvent">
  667. <short>Check current shift state. </short>
  668. <descr>
  669. <var>PollShiftStateEvent</var> returns the current shiftstate in a
  670. keyevent. This will return 0 if there is no key event pending.
  671. </descr>
  672. <errors>
  673. None.
  674. </errors>
  675. <seealso>
  676. <link id="PollKeyEvent"/>
  677. <link id="GetKeyEvent"/>
  678. </seealso>
  679. <example file="kbdex/ex6"/>
  680. </element>
  681. <element name="PutKeyEvent">
  682. <short>Put a key event in the event queue.</short>
  683. <descr>
  684. <var>PutKeyEvent</var> adds the given <var>KeyEvent</var> to the input
  685. queue. Please note that depending on the implementation this
  686. can hold only one value, i.e. when calling <var>PutKeyEvent</var>
  687. multiple times, only the last pushed key will be remembered.
  688. </descr>
  689. <errors>
  690. None
  691. </errors>
  692. <seealso>
  693. <link id="PollKeyEvent"/>
  694. <link id="GetKeyEvent"/>
  695. </seealso>
  696. <example file="kbdex/ex5"/>
  697. </element>
  698. <element name="SetKeyboardDriver">
  699. <short>Set a new keyboard driver.</short>
  700. <descr>
  701. <p>
  702. <var>SetKeyBoardDriver</var> sets the keyboard driver to <var>Driver</var>, if the
  703. current keyboard driver is not yet initialized. If the current
  704. keyboard driver is initialized, then <var>SetKeyboardDriver</var> does
  705. nothing. Before setting the driver, the currently active driver should
  706. be disabled with a call to <link id="DoneKeyboard"/>.
  707. </p>
  708. <p>
  709. The function returns <var>True</var> if the driver was set, <var>False</var> if not.
  710. </p>
  711. <p>
  712. For more information on setting the keyboard driver, see <link id="kbddriver"/>.
  713. </p>
  714. </descr>
  715. <errors>
  716. None.
  717. </errors>
  718. <seealso>
  719. <link id="GetKeyboardDriver"/>
  720. <link id="DoneKeyboard"/>.
  721. </seealso>
  722. </element>
  723. <element name="ShiftStateToString">
  724. <short>Return description of key event shift state</short>
  725. <descr>
  726. <p>
  727. <var>ShiftStateToString</var> returns a string description of the shift state
  728. of the key event <var>KeyEvent</var>. This can be an empty string.
  729. </p>
  730. <p>
  731. The shift state is described using the strings in the <var>SShift</var> constant.
  732. </p>
  733. <p>
  734. For an example, see <link id="PollShiftStateEvent"/>.
  735. </p>
  736. </descr>
  737. <errors>
  738. None.
  739. </errors>
  740. <seealso>
  741. <link id="FunctionKeyName"/>
  742. <link id="KeyEventToString"/>
  743. </seealso>
  744. </element>
  745. <element name="TranslateKeyEvent">
  746. <short>Translate raw event to ascii key event</short>
  747. <descr>
  748. <p>
  749. <var>TranslateKeyEvent</var> performs ASCII translation of the <var>KeyEvent</var>.
  750. It translates a physical key to a function key if the key is a function key,
  751. and translates the physical key to the ordinal of the ascii character if
  752. there is an equivalent character key.
  753. </p>
  754. <p>
  755. For an example, see <link id="GetKeyEvent"/>
  756. </p>
  757. </descr>
  758. <errors>
  759. None.
  760. </errors>
  761. <seealso>
  762. <link id="TranslateKeyEventUniCode"/>
  763. </seealso>
  764. </element>
  765. <element name="TranslateKeyEventUniCode">
  766. <short>Translate raw event to UNICode key event</short>
  767. <descr>
  768. <var>TranslateKeyEventUniCode</var> performs Unicode translation of the
  769. <var>KeyEvent</var>. It is not yet implemented for all platforms.
  770. </descr>
  771. <errors>
  772. If the function is not yet implemented, then the <var>ErrorCode</var> of the
  773. <file>system</file> unit will be set to <var>errKbdNotImplemented</var>
  774. </errors>
  775. <seealso>
  776. <link id="TranslateKeyEvent"/>
  777. </seealso>
  778. </element>
  779. <topic name="kbdscancode">
  780. <short>Keyboard scan codes</short>
  781. <descr>
  782. <p>
  783. Special physical keys are encoded with the DOS scan codes for these keys
  784. in the second byte of the <link id="TKeyEvent"/> type.
  785. A complete list of scan codes can be found in the below table.
  786. This is the list of keys that is used by the default key event translation mechanism.
  787. When writing a keyboard driver, either these constants should be returned
  788. by the various key event functions, or the <var>TranslateKeyEvent</var> hook
  789. should be implemented by the driver.
  790. </p>
  791. <table border="1">
  792. <caption>Key Scancodes</caption>
  793. <th><td>Code</td><td>Key</td><td>Code</td><td>Key</td><td>Code</td><td>Key</td></th>
  794. <tr><td>00 </td><td> NoKey </td><td> 3D </td><td> F3 </td><td> 70 </td><td> ALT-F9 </td></tr>
  795. <tr><td>01 </td><td> ALT-Esc </td><td> 3E </td><td> F4 </td><td> 71 </td><td> ALT-F10 </td></tr>
  796. <tr><td>02 </td><td> ALT-Space </td><td> 3F </td><td> F5 </td><td> 72 </td><td> CTRL-PrtSc </td></tr>
  797. <tr><td>04 </td><td> CTRL-Ins </td><td> 40 </td><td> F6 </td><td> 73 </td><td> CTRL-Left </td></tr>
  798. <tr><td>05 </td><td> SHIFT-Ins </td><td> 41 </td><td> F7 </td><td> 74 </td><td> CTRL-Right </td></tr>
  799. <tr><td>06 </td><td> CTRL-Del </td><td> 42 </td><td> F8 </td><td> 75 </td><td> CTRL-end </td></tr>
  800. <tr><td>07 </td><td> SHIFT-Del </td><td> 43 </td><td> F9 </td><td> 76 </td><td> CTRL-PgDn </td></tr>
  801. <tr><td>08 </td><td> ALT-Back </td><td> 44 </td><td> F10 </td><td> 77 </td><td> CTRL-Home </td></tr>
  802. <tr><td>09 </td><td> ALT-SHIFT-Back </td><td> 47 </td><td> Home </td><td> 78 </td><td> ALT-1 </td></tr>
  803. <tr><td>0F </td><td> SHIFT-Tab </td><td> 48 </td><td> Up </td><td> 79 </td><td> ALT-2 </td></tr>
  804. <tr><td>10 </td><td> ALT-Q </td><td> 49 </td><td> PgUp </td><td> 7A </td><td> ALT-3 </td></tr>
  805. <tr><td>11 </td><td> ALT-W </td><td> 4B </td><td> Left </td><td> 7B </td><td> ALT-4 </td></tr>
  806. <tr><td>12 </td><td> ALT-E </td><td> 4C </td><td> Center </td><td> 7C </td><td> ALT-5 </td></tr>
  807. <tr><td>13 </td><td> ALT-R </td><td> 4D </td><td> Right </td><td> 7D </td><td> ALT-6 </td></tr>
  808. <tr><td>14 </td><td> ALT-T </td><td> 4E </td><td> ALT-GrayPlus </td><td> 7E </td><td> ALT-7 </td></tr>
  809. <tr><td>15 </td><td> ALT-Y </td><td> 4F </td><td> end </td><td> 7F </td><td> ALT-8 </td></tr>
  810. <tr><td>16 </td><td> ALT-U </td><td> 50 </td><td> Down </td><td> 80 </td><td> ALT-9 </td></tr>
  811. <tr><td>17 </td><td> ALT-I </td><td> 51 </td><td> PgDn </td><td> 81 </td><td> ALT-0 </td></tr>
  812. <tr><td>18 </td><td> ALT-O </td><td> 52 </td><td> Ins </td><td> 82 </td><td> ALT-Minus </td></tr>
  813. <tr><td>19 </td><td> ALT-P </td><td> 53 </td><td> Del </td><td> 83 </td><td> ALT-Equal </td></tr>
  814. <tr><td>1A </td><td> ALT-LftBrack </td><td> 54 </td><td> SHIFT-F1 </td><td> 84 </td><td> CTRL-PgUp </td></tr>
  815. <tr><td>1B </td><td> ALT-RgtBrack </td><td> 55 </td><td> SHIFT-F2 </td><td> 85 </td><td> F11 </td></tr>
  816. <tr><td>1E </td><td> ALT-A </td><td> 56 </td><td> SHIFT-F3 </td><td> 86 </td><td> F12 </td></tr>
  817. <tr><td>1F </td><td> ALT-S </td><td> 57 </td><td> SHIFT-F4 </td><td> 87 </td><td> SHIFT-F11 </td></tr>
  818. <tr><td>20 </td><td> ALT-D </td><td> 58 </td><td> SHIFT-F5 </td><td> 88 </td><td> SHIFT-F12 </td></tr>
  819. <tr><td>21 </td><td> ALT-F </td><td> 59 </td><td> SHIFT-F6 </td><td> 89 </td><td> CTRL-F11 </td></tr>
  820. <tr><td>22 </td><td> ALT-G </td><td> 5A </td><td> SHIFT-F7 </td><td> 8A </td><td> CTRL-F12 </td></tr>
  821. <tr><td>23 </td><td> ALT-H </td><td> 5B </td><td> SHIFT-F8 </td><td> 8B </td><td> ALT-F11 </td></tr>
  822. <tr><td>24 </td><td> ALT-J </td><td> 5C </td><td> SHIFT-F9 </td><td> 8C </td><td> ALT-F12 </td></tr>
  823. <tr><td>25 </td><td> ALT-K </td><td> 5D </td><td> SHIFT-F10 </td><td> 8D </td><td> CTRL-Up </td></tr>
  824. <tr><td>26 </td><td> ALT-L </td><td> 5E </td><td> CTRL-F1 </td><td> 8E </td><td> CTRL-Minus </td></tr>
  825. <tr><td>27 </td><td> ALT-SemiCol </td><td> 5F </td><td> CTRL-F2 </td><td> 8F </td><td> CTRL-Center </td></tr>
  826. <tr><td>28 </td><td> ALT-Quote </td><td> 60 </td><td> CTRL-F3 </td><td> 90 </td><td> CTRL-GreyPlus </td></tr>
  827. <tr><td>29 </td><td> ALT-OpQuote </td><td> 61 </td><td> CTRL-F4 </td><td> 91 </td><td> CTRL-Down </td></tr>
  828. <tr><td>2B </td><td> ALT-BkSlash </td><td> 62 </td><td> CTRL-F5 </td><td> 94 </td><td> CTRL-Tab </td></tr>
  829. <tr><td>2C </td><td> ALT-Z </td><td> 63 </td><td> CTRL-F6 </td><td> 97 </td><td> ALT-Home </td></tr>
  830. <tr><td>2D </td><td> ALT-X </td><td> 64 </td><td> CTRL-F7 </td><td> 98 </td><td> ALT-Up </td></tr>
  831. <tr><td>2E </td><td> ALT-C </td><td> 65 </td><td> CTRL-F8 </td><td> 99 </td><td> ALT-PgUp </td></tr>
  832. <tr><td>2F </td><td> ALT-V </td><td> 66 </td><td> CTRL-F9 </td><td> 9B </td><td> ALT-Left </td></tr>
  833. <tr><td>30 </td><td> ALT-B </td><td> 67 </td><td> CTRL-F10 </td><td> 9D </td><td> ALT-Right </td></tr>
  834. <tr><td>31 </td><td> ALT-N </td><td> 68 </td><td> ALT-F1 </td><td> 9F </td><td> ALT-end </td></tr>
  835. <tr><td>32 </td><td> ALT-M </td><td> 69 </td><td> ALT-F2 </td><td> A0 </td><td> ALT-Down </td></tr>
  836. <tr><td>33 </td><td> ALT-Comma </td><td> 6A </td><td> ALT-F3 </td><td> A1 </td><td> ALT-PgDn </td></tr>
  837. <tr><td>34 </td><td> ALT-Period </td><td> 6B </td><td> ALT-F4 </td><td> A2 </td><td> ALT-Ins </td></tr>
  838. <tr><td>35 </td><td> ALT-Slash </td><td> 6C </td><td> ALT-F5 </td><td> A3 </td><td> ALT-Del </td></tr>
  839. <tr><td>37 </td><td> ALT-GreyAst </td><td> 6D </td><td> ALT-F6 </td><td> A5 </td><td> ALT-Tab </td></tr>
  840. <tr><td>3B </td><td> F1 </td><td> 6E </td><td> ALT-F7 </td><td> </td><td> </td></tr>
  841. <tr><td>3C </td><td> F2 </td><td> 6F </td><td> ALT-F8 </td><td> </td><td> </td></tr>
  842. </table>
  843. <p>
  844. A list of scan codes for special keys and combinations with the SHIFT, ALT
  845. and CTRL keys can be found in the following table: They are for quick reference
  846. only.
  847. </p>
  848. <table border="1">
  849. <caption>Special keys scan codes</caption>
  850. <th><td>Key </td><td> Code </td><td> SHIFT-Key </td><td> CTRL-Key </td><td> Alt-Key</td></th>
  851. <tr><td>NoKey </td><td> 00 </td><td> </td><td> </td><td> </td></tr>
  852. <tr><td>F1 </td><td> 3B </td><td> 54 </td><td> 5E </td><td> 68 </td></tr>
  853. <tr><td>F2 </td><td> 3C </td><td> 55 </td><td> 5F </td><td> 69 </td></tr>
  854. <tr><td>F3 </td><td> 3D </td><td> 56 </td><td> 60 </td><td> 6A </td></tr>
  855. <tr><td>F4 </td><td> 3E </td><td> 57 </td><td> 61 </td><td> 6B </td></tr>
  856. <tr><td>F5 </td><td> 3F </td><td> 58 </td><td> 62 </td><td> 6C </td></tr>
  857. <tr><td>F6 </td><td> 40 </td><td> 59 </td><td> 63 </td><td> 6D </td></tr>
  858. <tr><td>F7 </td><td> 41 </td><td> 5A </td><td> 64 </td><td> 6E </td></tr>
  859. <tr><td>F8 </td><td> 42 </td><td> 5A </td><td> 65 </td><td> 6F </td></tr>
  860. <tr><td>F9 </td><td> 43 </td><td> 5B </td><td> 66 </td><td> 70 </td></tr>
  861. <tr><td>F10 </td><td> 44 </td><td> 5C </td><td> 67 </td><td> 71 </td></tr>
  862. <tr><td>F11 </td><td> 85 </td><td> 87 </td><td> 89 </td><td> 8B </td></tr>
  863. <tr><td>F12 </td><td> 86 </td><td> 88 </td><td> 8A </td><td> 8C </td></tr>
  864. <tr><td>Home </td><td> 47 </td><td> </td><td> 77 </td><td> 97 </td></tr>
  865. <tr><td>Up </td><td> 48 </td><td> </td><td> 8D </td><td> 98 </td></tr>
  866. <tr><td>PgUp </td><td> 49 </td><td> </td><td> 84 </td><td> 99 </td></tr>
  867. <tr><td>Left </td><td> 4B </td><td> </td><td> 73 </td><td> 9B </td></tr>
  868. <tr><td>Center </td><td> 4C </td><td> </td><td> 8F </td><td> </td></tr>
  869. <tr><td>Right </td><td> 4D </td><td> </td><td> 74 </td><td> 9D </td></tr>
  870. <tr><td>end </td><td> 4F </td><td> </td><td> 75 </td><td> 9F </td></tr>
  871. <tr><td>Down </td><td> 50 </td><td> </td><td> 91 </td><td> A0 </td></tr>
  872. <tr><td>PgDn </td><td> 51 </td><td> </td><td> 76 </td><td> A1 </td></tr>
  873. <tr><td>Ins </td><td> 52 </td><td> 05 </td><td> 04 </td><td> A2 </td></tr>
  874. <tr><td>Del </td><td> 53 </td><td> 07 </td><td> 06 </td><td> A3 </td></tr>
  875. <tr><td>Tab </td><td> 8 </td><td> 0F </td><td> 94 </td><td> A5 </td></tr>
  876. <tr><td>GreyPlus </td><td> </td><td> </td><td> 90 </td><td> 4E </td></tr>
  877. </table>
  878. </descr>
  879. </topic>
  880. <topic name="kbddriver">
  881. <short>Writing a keyboard driver</short>
  882. <descr>
  883. <p>
  884. Writing a keyboard driver means that hooks must be created for most of the
  885. keyboard unit functions. The <var>TKeyBoardDriver</var> record contains a field
  886. for each of the possible hooks:
  887. </p>
  888. <code>
  889. TKeyboardDriver = Record
  890. InitDriver : Procedure;
  891. DoneDriver : Procedure;
  892. GetKeyEvent : Function : TKeyEvent;
  893. PollKeyEvent : Function : TKeyEvent;
  894. GetShiftState : Function : Byte;
  895. TranslateKeyEvent : Function (KeyEvent: TKeyEvent): TKeyEvent;
  896. TranslateKeyEventUniCode: Function (KeyEvent: TKeyEvent): TKeyEvent;
  897. end;
  898. </code>
  899. <p>
  900. The meaning of these hooks is explained below:
  901. </p>
  902. <dl>
  903. <dt>InitDriver</dt>
  904. <dd> Called to initialize and enable the driver.
  905. Guaranteed to be called only once. This should initialize all needed things
  906. for the driver.
  907. </dd>
  908. <dt>DoneDriver</dt>
  909. <dd> Called to disable and clean up the driver. Guaranteed to be
  910. called after a call to <var>initDriver</var>. This should clean up all
  911. things initialized by <var>InitDriver</var>.
  912. </dd>
  913. <dt>GetKeyEvent</dt>
  914. <dd> Called by <link id="GetKeyEvent"/>. Must wait for and return the
  915. next key event. It should NOT store keys.
  916. </dd>
  917. <dt>PollKeyEvent</dt>
  918. <dd> Called by <link id="PollKeyEvent"/>. It must return the next key
  919. event if there is one. Should not store keys.
  920. </dd>
  921. <dt>GetShiftState</dt>
  922. <dd> Called by <link id="PollShiftStateEvent"/>. Must return the current
  923. shift state.
  924. </dd>
  925. <dt>TranslateKeyEvent</dt>
  926. <dd> Should translate a raw key event to a cOrrect
  927. key event, i.e. should fill in the shiftstate and convert function key
  928. scancodes to function key keycodes. If the
  929. <var>TranslateKeyEvent</var> is not filled in, a default translation function
  930. will be called which converts the known scancodes from the tables in the
  931. previous section to a correct keyevent.
  932. </dd>
  933. <dt>TranslateKeyEventUniCode</dt>
  934. <dd> Should translate a key event to a unicode key
  935. representation.
  936. </dd>
  937. </dl>
  938. <p>
  939. Strictly speaking, only the <var>GetKeyEvent</var> and <var>PollKeyEvent</var>
  940. hooks must be implemented for the driver to function correctly.
  941. </p>
  942. <p>
  943. The example unit demonstrates how a keyboard driver can be installed.
  944. It takes the installed driver, and hooks into the <var>GetKeyEvent</var>
  945. function to register and log the key events in a file. This driver
  946. can work on top of any other driver, as long as it is inserted in the
  947. <var>uses</var> clause <em> after</em> the real driver unit, and the real driver unit
  948. should set the driver record in its initialization section.
  949. </p>
  950. <p>
  951. Note that with a simple extension of this unit could be used to make a
  952. driver that is capable of recording and storing a set of keyboard strokes,
  953. and replaying them at a later time, so a 'keyboard macro' capable driver.
  954. This driver could sit on top of any other driver.
  955. </p>
  956. </descr>
  957. <example file="kbdex/logkeys"/>
  958. <example file="kbdex/ex9"/>
  959. </topic>
  960. </module>
  961. </package>
  962. </fpdoc-descriptions>