keyboard.pp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. Keyboard unit for OS/2
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit Keyboard;
  14. interface
  15. {$i keybrdh.inc}
  16. implementation
  17. uses
  18. KbdCalls, DosCalls;
  19. {$i keyboard.inc}
  20. const
  21. DefaultKeyboard = 0;
  22. Handle: word = DefaultKeyboard;
  23. procedure SysInitKeyboard;
  24. var
  25. K: TKbdInfo;
  26. begin
  27. if KbdGetFocus (IO_Wait, DefaultKeyboard) = No_Error then
  28. begin
  29. if KbdOpen (Handle) <> No_Error then Handle := DefaultKeyboard;
  30. KbdFlushBuffer (Handle);
  31. KbdFreeFocus (DefaultKeyboard);
  32. KbdGetFocus (IO_Wait, Handle);
  33. K.cb := 10;
  34. KbdGetStatus (K, Handle);
  35. K.fsMask := $14;
  36. KbdSetStatus (K, Handle);
  37. end;
  38. end;
  39. procedure SysDoneKeyboard;
  40. begin
  41. KbdFreeFocus (Handle);
  42. if KbdGetFocus (IO_Wait, DefaultKeyboard) = No_Error then
  43. begin
  44. KbdClose (Handle);
  45. Handle := DefaultKeyboard;
  46. KbdFreeFocus (DefaultKeyboard);
  47. end;
  48. end;
  49. function SysGetKeyEvent: TKeyEvent;
  50. var
  51. K: TKbdKeyInfo;
  52. begin
  53. KbdGetFocus (IO_Wait, Handle);
  54. while (KbdCharIn (K, IO_Wait, Handle) <> No_Error)
  55. or (K.fbStatus and $40 = 0) do
  56. DosSleep (5);
  57. with K do
  58. begin
  59. if (byte (chChar) = $E0) and (fbStatus and 2 <> 0) then chChar := #0;
  60. SysGetKeyEvent := cardinal ($0300 or fsState and $F) shl 16 or
  61. cardinal (byte (chScan)) shl 8 or byte (chChar);
  62. end;
  63. end;
  64. function SysPollKeyEvent: TKeyEvent;
  65. var
  66. K: TKbdKeyInfo;
  67. Key : TKeyEvent;
  68. begin
  69. Key:=0;
  70. KbdGetFocus (IO_NoWait, Handle);
  71. if (KbdPeek (K, Handle) <> No_Error) or
  72. (K.fbStatus and $40 = 0) then
  73. FillChar (K, SizeOf (K), 0)
  74. else
  75. with K do
  76. begin
  77. if (byte (chChar) = $E0) and (fbStatus and 2 <> 0) then
  78. chChar := #0;
  79. Key:= cardinal ($0300 or fsState and $F) shl 16 or
  80. cardinal (byte (chScan)) shl 8 or byte (chChar);
  81. end;
  82. if (Key and $FFFF)=0 then
  83. Key := 0;
  84. SysPollKeyEvent:=Key;
  85. end;
  86. function SysGetShiftState: Byte;
  87. var
  88. K: TKbdInfo;
  89. begin
  90. KbdGetFocus (IO_NoWait, Handle);
  91. KbdGetStatus (K, Handle);
  92. SysGetShiftState:=(K.fsState and $F);
  93. end;
  94. Const
  95. SysKeyboardDriver : TKeyboardDriver = (
  96. InitDriver : @SysInitKeyBoard;
  97. DoneDriver : @SysDoneKeyBoard;
  98. GetKeyevent : @SysGetKeyEvent;
  99. PollKeyEvent : @SysPollKeyEvent;
  100. GetShiftState : @SysGetShiftState;
  101. TranslateKeyEvent : Nil;
  102. TranslateKeyEventUnicode : Nil;
  103. );
  104. begin
  105. SetKeyBoardDriver(SysKeyBoardDriver);
  106. end.
  107. {
  108. $Log$
  109. Revision 1.4 2002-03-03 21:08:33 hajny
  110. * SysPollKeyEvent fixed
  111. Revision 1.3 2001/09/21 21:33:36 michael
  112. + Merged driver support from fixbranch
  113. Revision 1.2.2.2 2001/09/21 21:20:43 michael
  114. + Added support for keyboard driver.
  115. + Added DefaultTranslateKeyEvent,DefaultTranslateKeyEventUnicode
  116. + PendingKeyEvent variable no longer public. Handling of this variable is
  117. now done entirely by global functions. System dependent code should not
  118. need it, it is set automatically.
  119. + InitVideo DoneVideo will check whether the keyboard is initialized or not.
  120. Revision 1.2.2.1 2001/01/30 21:52:02 peter
  121. * moved api utils to rtl
  122. Revision 1.2 2001/01/13 12:01:07 hajny
  123. * ErrorHandler correction
  124. Revision 1.1 2001/01/13 11:03:58 peter
  125. * API 2 RTL commit
  126. }