keyboard.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2004 by the Free Pascal development team.
  5. Keyboard unit for netware libc
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit Keyboard;
  13. interface
  14. {$i keybrdh.inc}
  15. implementation
  16. uses Libc;
  17. {$i keyboard.inc}
  18. procedure SysInitKeyboard;
  19. begin
  20. PendingKeyEvent := 0;
  21. end;
  22. function SysGetKeyEvent: TKeyEvent;
  23. var Ktype,Kvalue,Kstatus,Kscancode : byte;
  24. begin
  25. if PendingKeyEvent<>0 then
  26. begin
  27. SysGetKeyEvent:=PendingKeyEvent;
  28. PendingKeyEvent:=0;
  29. exit;
  30. end;
  31. Libc.GetKey(Libc.GetScreenHandle,Ktype,Kvalue,Kstatus,Kscancode,0{ ??? linesToProtect:size_t});
  32. with TKeyRecord (SysGetKeyEvent) do
  33. begin
  34. Case Ktype of
  35. ENTER_KEY : begin
  36. KeyCode := $1c0d; Flags := 3;
  37. end;
  38. ESCAPE_KEY : begin
  39. KeyCode := $011b; Flags := 3;
  40. end;
  41. BACKSPACE_KEY : begin
  42. KeyCode := $0e08; Flags := 3;
  43. end;
  44. NORMAL_KEY : begin
  45. if KStatus AND ALT_KEY_HELD > 0 then KValue := 0;
  46. IF (KValue = 9) and ((KStatus and SHIFT_KEY_HELD) > 0) then KValue := 0;
  47. KeyCode := (Kscancode shl 8) + KValue;
  48. Flags := 3;
  49. end;
  50. FUNCTION_KEY,
  51. DELETE_KEY,
  52. INSERT_KEY,
  53. CURSOR_DOWN_KEY,
  54. CURSOR_UP_KEY,
  55. CURSOR_RIGHT_KEY,
  56. CURSOR_LEFT_KEY,
  57. CURSOR_HOME_KEY,
  58. CURSOR_END_KEY,
  59. CURSOR_PUP_KEY,
  60. CURSOR_PDOWN_KEY : begin
  61. KeyCode := KScancode shl 8;
  62. Flags := 3;
  63. end;
  64. end;
  65. ShiftState := 0;
  66. if KStatus AND SHIFT_KEY_HELD > 0 then ShiftState := ShiftState or kbShift;
  67. if KStatus AND CTRL_KEY_HELD > 0 then ShiftState := ShiftState or kbCtrl;
  68. if KStatus AND ALT_KEY_HELD > 0 then ShiftState := ShiftState or kbAlt;
  69. end;
  70. end;
  71. function SysPollKeyEvent: TKeyEvent;
  72. begin
  73. if PendingKeyEvent<>0 then
  74. exit(PendingKeyEvent);
  75. if Libc.CheckKeyStatus (Libc.GetScreenHandle) <> 0 then
  76. begin
  77. PendingKeyEvent := SysGetKeyEvent;
  78. SysPollKeyEvent := PendingKeyEvent;
  79. end else
  80. begin
  81. SysPollKeyEvent := 0;
  82. //NXThreadYield;
  83. Delay(50);
  84. end;
  85. end;
  86. function SysPollShiftStateEvent: TKeyEvent;
  87. begin
  88. SysPollShiftStateEvent:=0;
  89. end;
  90. function SysGetShiftState: Byte;
  91. begin
  92. SysGetShiftState:=0;
  93. end;
  94. function SysTranslateKeyEvent(KeyEvent: TKeyEvent): TKeyEvent;
  95. begin
  96. {if KeyEvent and $03000000 = $03000000 then
  97. KeyEvent := KeyEvent - $03000000;}
  98. SysTranslateKeyEvent := KeyEvent;
  99. end;
  100. Const
  101. SysKeyboardDriver : TKeyboardDriver = (
  102. InitDriver : Nil;
  103. DoneDriver : Nil;
  104. GetKeyevent : @SysGetKeyEvent;
  105. PollKeyEvent : @SysPollKeyEvent;
  106. GetShiftState : @SysGetShiftState;
  107. TranslateKeyEvent : nil; //@SysTranslateKeyEvent;
  108. TranslateKeyEventUnicode : Nil;
  109. );
  110. begin
  111. KeyboardInitialized := false;
  112. PendingKeyEvent := 0;
  113. SetKeyBoardDriver(SysKeyBoardDriver);
  114. end.
  115. {
  116. $Log$
  117. Revision 1.1 2004-09-12 20:51:22 armin
  118. * added keyboard and video
  119. * a lot of fixes
  120. Revision 1.4 2002/09/07 16:01:20 peter
  121. * old logs removed and tabs fixed
  122. Revision 1.3 2002/03/08 19:02:59 armin
  123. Changes for new style (TKeyboardDriver record)
  124. }