keyboard.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 by the Free Pascal development team.
  4. Keyboard unit for netware libc
  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. unit Keyboard;
  12. interface
  13. {$i keybrdh.inc}
  14. implementation
  15. uses Libc;
  16. {$i keyboard.inc}
  17. procedure SysInitKeyboard;
  18. begin
  19. PendingKeyEvent := 0;
  20. end;
  21. function SysGetKeyEvent: TKeyEvent;
  22. var Ktype,Kvalue,Kstatus,Kscancode : byte;
  23. begin
  24. if PendingKeyEvent<>0 then
  25. begin
  26. SysGetKeyEvent:=PendingKeyEvent;
  27. PendingKeyEvent:=0;
  28. exit;
  29. end;
  30. Libc.GetKey(Libc.GetScreenHandle,Ktype,Kvalue,Kstatus,Kscancode,0{ ??? linesToProtect:size_t});
  31. with TKeyRecord (SysGetKeyEvent) do
  32. begin
  33. Case Ktype of
  34. ENTER_KEY : begin
  35. KeyCode := $1c0d; Flags := 3;
  36. end;
  37. ESCAPE_KEY : begin
  38. KeyCode := $011b; Flags := 3;
  39. end;
  40. BACKSPACE_KEY : begin
  41. KeyCode := $0e08; Flags := 3;
  42. end;
  43. NORMAL_KEY : begin
  44. if KStatus AND ALT_KEY_HELD > 0 then KValue := 0;
  45. IF (KValue = 9) and ((KStatus and SHIFT_KEY_HELD) > 0) then KValue := 0;
  46. KeyCode := (Kscancode shl 8) + KValue;
  47. Flags := 3;
  48. end;
  49. FUNCTION_KEY,
  50. DELETE_KEY,
  51. INSERT_KEY,
  52. CURSOR_DOWN_KEY,
  53. CURSOR_UP_KEY,
  54. CURSOR_RIGHT_KEY,
  55. CURSOR_LEFT_KEY,
  56. CURSOR_HOME_KEY,
  57. CURSOR_END_KEY,
  58. CURSOR_PUP_KEY,
  59. CURSOR_PDOWN_KEY : begin
  60. KeyCode := KScancode shl 8;
  61. Flags := 3;
  62. end;
  63. end;
  64. ShiftState := 0;
  65. if KStatus AND SHIFT_KEY_HELD > 0 then ShiftState := ShiftState or kbShift;
  66. if KStatus AND CTRL_KEY_HELD > 0 then ShiftState := ShiftState or kbCtrl;
  67. if KStatus AND ALT_KEY_HELD > 0 then ShiftState := ShiftState or kbAlt;
  68. end;
  69. end;
  70. function SysPollKeyEvent: TKeyEvent;
  71. begin
  72. if PendingKeyEvent<>0 then
  73. exit(PendingKeyEvent);
  74. if Libc.CheckKeyStatus (Libc.GetScreenHandle) <> 0 then
  75. begin
  76. PendingKeyEvent := SysGetKeyEvent;
  77. SysPollKeyEvent := PendingKeyEvent;
  78. end else
  79. begin
  80. SysPollKeyEvent := 0;
  81. //NXThreadYield;
  82. Delay(50);
  83. end;
  84. end;
  85. function SysPollShiftStateEvent: TKeyEvent;
  86. begin
  87. SysPollShiftStateEvent:=0;
  88. end;
  89. function SysGetShiftState: Byte;
  90. begin
  91. SysGetShiftState:=0;
  92. end;
  93. function SysTranslateKeyEvent(KeyEvent: TKeyEvent): TKeyEvent;
  94. begin
  95. {if KeyEvent and $03000000 = $03000000 then
  96. KeyEvent := KeyEvent - $03000000;}
  97. SysTranslateKeyEvent := KeyEvent;
  98. end;
  99. Const
  100. SysKeyboardDriver : TKeyboardDriver = (
  101. InitDriver : Nil;
  102. DoneDriver : Nil;
  103. GetKeyevent : @SysGetKeyEvent;
  104. PollKeyEvent : @SysPollKeyEvent;
  105. GetShiftState : @SysGetShiftState;
  106. TranslateKeyEvent : nil; //@SysTranslateKeyEvent;
  107. TranslateKeyEventUnicode : Nil;
  108. );
  109. begin
  110. KeyboardInitialized := false;
  111. PendingKeyEvent := 0;
  112. SetKeyBoardDriver(SysKeyBoardDriver);
  113. end.