keybrdh.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. const
  12. { We have an errorcode base of 1010 }
  13. errKbdBase = 1010;
  14. errKbdInitError = errKbdBase + 0;
  15. errKbdNotImplemented = errKbdBase + 1;
  16. type
  17. TKeyEvent = Longint;
  18. { The structure of a TKeyEvent follows in LSB-MSB order:
  19. 2 bytes: depending on flags either the physical representation of a key
  20. (under DOS scancode, ascii code pair), or the translated
  21. ASCII/unicode character
  22. 1 byte: shift-state when this key was pressed (or shortly after)
  23. 1 byte: flags, the following flags are defined:
  24. bit0-1
  25. 0: the lowest two bytes is the translated ASCII value
  26. 1: the lowest two bytes is the translated Unicode value
  27. (wide-char)
  28. 2: the lowest two bytes is a function key, and the lowest
  29. two bytes contains its platform independent code
  30. 3: the lowest two bytes is the physical representation
  31. bit2
  32. 0: the key is pressed
  33. 1: the key is released (This event is not guaranteed to occur on all platforms)
  34. bit3-7 undefined, should be 0
  35. If there are two keys returning the same char-code, there's no way to find
  36. out which one was pressed (Gray+ and Simple+). If you need to know which
  37. was pressed, you'll need to use the untranslated keycodes, which is system
  38. dependent. System dependent constants may be defined to cover those, with
  39. possibily having the same name (but different value). }
  40. { System independent function key codes }
  41. const
  42. kbdF1 = $FF01;
  43. kbdF2 = $FF02;
  44. kbdF3 = $FF03;
  45. kbdF4 = $FF04;
  46. kbdF5 = $FF05;
  47. kbdF6 = $FF06;
  48. kbdF7 = $FF07;
  49. kbdF8 = $FF08;
  50. kbdF9 = $FF09;
  51. kbdF10 = $FF0A;
  52. kbdF11 = $FF0B;
  53. kbdF12 = $FF0C;
  54. kbdF13 = $FF0D;
  55. kbdF14 = $FF0E;
  56. kbdF15 = $FF0F;
  57. kbdF16 = $FF10;
  58. kbdF17 = $FF11;
  59. kbdF18 = $FF12;
  60. kbdF19 = $FF13;
  61. kbdF20 = $FF14;
  62. { $15 - $1F reserved for future Fxx keys }
  63. kbdHome = $FF20;
  64. kbdUp = $FF21;
  65. kbdPgUp = $FF22;
  66. kbdLeft = $FF23;
  67. kbdMiddle = $FF24;
  68. kbdRight = $FF25;
  69. kbdEnd = $FF26;
  70. kbdDown = $FF27;
  71. kbdPgDn = $FF28;
  72. kbdInsert = $FF29;
  73. kbdDelete = $FF2A;
  74. { $2B - $2F reserved for future keypad keys }
  75. { possible flag values }
  76. kbASCII = $00;
  77. kbUniCode = $01;
  78. kbFnKey = $02;
  79. kbPhys = $03;
  80. kbReleased = $04;
  81. { shiftstate flags }
  82. kbLeftShift = 1;
  83. kbRightShift = 2;
  84. kbShift = kbLeftShift or kbRightShift;
  85. kbCtrl = 4;
  86. kbAlt = 8;
  87. var
  88. PendingKeyEvent : TKeyEvent;
  89. procedure InitKeyboard;
  90. { Initializes the keyboard interface, additional platform specific parameters
  91. can be passed by global variables (RawMode etc.) for the first implementation
  92. under DOS it does nothing }
  93. procedure DoneKeyboard;
  94. { Deinitializes the keyboard interface }
  95. function GetKeyEvent: TKeyEvent;
  96. { Returns the last keyevent, and waits for one if not available }
  97. procedure PutKeyEvent(KeyEvent: TKeyEvent);
  98. { Adds the given KeyEvent to the input queue. Please note that depending on
  99. the implementation this can hold only one value (NO FIFOs etc) }
  100. function PollKeyEvent: TKeyEvent;
  101. { Checks if a keyevent is available, and returns it if one is found. If no
  102. event is pending, it returns 0 }
  103. function PollShiftStateEvent: TKeyEvent;
  104. { Return the current shiftstate in a keyevent }
  105. function TranslateKeyEvent(KeyEvent: TKeyEvent): TKeyEvent;
  106. { Performs ASCII translation of the KeyEvent }
  107. function TranslateKeyEventUniCode(KeyEvent: TKeyEvent): TKeyEvent;
  108. { Performs Unicode translation of the KeyEvent }
  109. function GetKeyEventFlags(KeyEvent: TKeyEvent): Byte;
  110. { Returns the flags part of the given KeyEvent }
  111. function GetKeyEventChar(KeyEvent: TKeyEvent): Char;
  112. { Returns the charcode part of the given KeyEvent, if it contains a translated
  113. keycode }
  114. function GetKeyEventUniCode(KeyEvent: TKeyEvent): Word;
  115. { Returns the unicode part of the given KeyEvent, if it contains a translated
  116. unicode character }
  117. function GetKeyEventCode(KeyEvent: TKeyEvent): Word;
  118. { Returns the translated function keycode part of the given KeyEvent, if it
  119. contains a translated function keycode }
  120. function GetKeyEventShiftState(KeyEvent: TKeyEvent): Byte;
  121. { Returns the shift-state values of the given KeyEvent }
  122. function IsFunctionKey(KeyEvent: TKeyEvent): Boolean;
  123. { Returns true if the given key was a function key or not }
  124. {
  125. $Log$
  126. Revision 1.1 2001-01-13 11:13:12 peter
  127. * API 2 RTL
  128. }