keyboard.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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
  30. Handle := DefaultKeyboard;
  31. KbdFlushBuffer (Handle);
  32. KbdFreeFocus (DefaultKeyboard);
  33. KbdGetFocus (IO_Wait, Handle);
  34. K.cb := SizeOf (K);
  35. KbdGetStatus (K, Handle);
  36. K.fsMask := $14;
  37. KbdSetStatus (K, Handle);
  38. end;
  39. end;
  40. procedure SysDoneKeyboard;
  41. begin
  42. KbdFreeFocus (Handle);
  43. if KbdGetFocus (IO_Wait, DefaultKeyboard) = No_Error then
  44. begin
  45. KbdClose (Handle);
  46. Handle := DefaultKeyboard;
  47. KbdFreeFocus (DefaultKeyboard);
  48. end;
  49. end;
  50. function SysGetKeyEvent: TKeyEvent;
  51. var
  52. K: TKbdKeyInfo;
  53. begin
  54. KbdGetFocus (IO_Wait, Handle);
  55. while (KbdCharIn (K, IO_Wait, Handle) <> No_Error)
  56. or (K.fbStatus and $40 = 0) do
  57. DosSleep (5);
  58. with K do
  59. begin
  60. if (byte (chChar) = $E0) and (fbStatus and 2 <> 0) then chChar := #0;
  61. SysGetKeyEvent := cardinal ($0300 or fsState and $F) shl 16 or
  62. cardinal (byte (chScan)) shl 8 or byte (chChar);
  63. end;
  64. end;
  65. function SysPollKeyEvent: TKeyEvent;
  66. var
  67. K: TKbdKeyInfo;
  68. Key : TKeyEvent;
  69. begin
  70. Key:=0;
  71. KbdGetFocus (IO_NoWait, Handle);
  72. if (KbdPeek (K, Handle) <> No_Error) or
  73. (K.fbStatus and $40 = 0) then
  74. FillChar (K, SizeOf (K), 0)
  75. else
  76. with K do
  77. begin
  78. if (byte (chChar) = $E0) and (fbStatus and 2 <> 0) then
  79. chChar := #0;
  80. Key:= cardinal ($0300 or fsState and $F) shl 16 or
  81. cardinal (byte (chScan)) shl 8 or byte (chChar);
  82. end;
  83. if (Key and $FFFF)=0 then
  84. Key := 0;
  85. SysPollKeyEvent:=Key;
  86. end;
  87. function SysGetShiftState: Byte;
  88. var
  89. K: TKbdInfo;
  90. L: cardinal;
  91. begin
  92. KbdGetFocus (IO_NoWait, Handle);
  93. K.cb := SizeOf (K);
  94. if KbdGetStatus (K, Handle) = No_Error then
  95. SysGetShiftState := (K.fsState and $F)
  96. else
  97. SysGetShiftState := 0;
  98. end;
  99. Const
  100. SysKeyboardDriver : TKeyboardDriver = (
  101. InitDriver : @SysInitKeyBoard;
  102. DoneDriver : @SysDoneKeyBoard;
  103. GetKeyevent : @SysGetKeyEvent;
  104. PollKeyEvent : @SysPollKeyEvent;
  105. GetShiftState : @SysGetShiftState;
  106. TranslateKeyEvent : Nil;
  107. TranslateKeyEventUnicode : Nil;
  108. );
  109. begin
  110. SetKeyBoardDriver(SysKeyBoardDriver);
  111. end.
  112. {
  113. $Log$
  114. Revision 1.6 2004-12-27 22:26:43 hajny
  115. * SysGetShiftState fixed
  116. Revision 1.5 2002/09/07 16:01:24 peter
  117. * old logs removed and tabs fixed
  118. Revision 1.4 2002/03/03 21:08:33 hajny
  119. * SysPollKeyEvent fixed
  120. }