keyboard.pp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 go32v2
  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. go32;
  19. {$i keyboard.inc}
  20. procedure InitKeyboard;
  21. begin
  22. end;
  23. procedure DoneKeyboard;
  24. begin
  25. end;
  26. function GetKeyEvent: TKeyEvent;
  27. var
  28. regs : trealregs;
  29. begin
  30. if PendingKeyEvent<>0 then
  31. begin
  32. GetKeyEvent:=PendingKeyEvent;
  33. PendingKeyEvent:=0;
  34. exit;
  35. end;
  36. regs.ah:=$10;
  37. realintr($16,regs);
  38. if (regs.al=$e0) and (regs.ah<>0) then
  39. regs.al:=0;
  40. GetKeyEvent:=regs.ax or ((mem[$40:$17] and $f) shl 16);
  41. end;
  42. function PollKeyEvent: TKeyEvent;
  43. var
  44. regs : trealregs;
  45. begin
  46. if PendingKeyEvent<>0 then
  47. exit(PendingKeyEvent);
  48. regs.ah:=$11;
  49. realintr($16,regs);
  50. if (regs.realflags and zeroflag<>0) then
  51. exit(0);
  52. if (regs.al=$e0) and (regs.ah<>0) then
  53. regs.al:=0;
  54. PollKeyEvent:=regs.ax or ((mem[$40:$17] and $f) shl 16);
  55. end;
  56. function PollShiftStateEvent: TKeyEvent;
  57. begin
  58. PollShiftStateEvent:=((mem[$40:$17] and $f) shl 16);
  59. end;
  60. { Function key translation }
  61. type
  62. TTranslationEntry = packed record
  63. Min, Max: Byte;
  64. Offset: Word;
  65. end;
  66. const
  67. TranslationTableEntries = 12;
  68. TranslationTable: array [1..TranslationTableEntries] of TTranslationEntry =
  69. ((Min: $3B; Max: $44; Offset: kbdF1), { function keys F1-F10 }
  70. (Min: $54; Max: $5D; Offset: kbdF1), { Shift fn keys F1-F10 }
  71. (Min: $5E; Max: $67; Offset: kbdF1), { Ctrl fn keys F1-F10 }
  72. (Min: $68; Max: $71; Offset: kbdF1), { Alt fn keys F1-F10 }
  73. (Min: $85; Max: $86; Offset: kbdF11), { function keys F11-F12 }
  74. (Min: $87; Max: $88; Offset: kbdF11), { Shift+function keys F11-F12 }
  75. (Min: $89; Max: $8A; Offset: kbdF11), { Ctrl+function keys F11-F12 }
  76. (Min: $8B; Max: $8C; Offset: kbdF11), { Alt+function keys F11-F12 }
  77. (Min: 71; Max: 73; Offset: kbdHome), { Keypad keys kbdHome-kbdPgUp }
  78. (Min: 75; Max: 77; Offset: kbdLeft), { Keypad keys kbdLeft-kbdRight }
  79. (Min: 79; Max: 81; Offset: kbdEnd), { Keypad keys kbdEnd-kbdPgDn }
  80. (Min: $52; Max: $53; Offset: kbdInsert));
  81. function TranslateKeyEvent(KeyEvent: TKeyEvent): TKeyEvent;
  82. var
  83. I: Integer;
  84. ScanCode: Byte;
  85. begin
  86. if KeyEvent and $03000000 = $03000000 then
  87. begin
  88. if KeyEvent and $000000FF <> 0 then
  89. begin
  90. TranslateKeyEvent := KeyEvent and $00FFFFFF;
  91. exit;
  92. end
  93. else
  94. begin
  95. { This is a function key }
  96. ScanCode := (KeyEvent and $0000FF00) shr 8;
  97. for I := 1 to TranslationTableEntries do
  98. begin
  99. if (TranslationTable[I].Min <= ScanCode) and (ScanCode <= TranslationTable[I].Max) then
  100. begin
  101. TranslateKeyEvent := $02000000 + (KeyEvent and $00FF0000) +
  102. (ScanCode - TranslationTable[I].Min) + TranslationTable[I].Offset;
  103. exit;
  104. end;
  105. end;
  106. end;
  107. end;
  108. TranslateKeyEvent := KeyEvent;
  109. end;
  110. function TranslateKeyEventUniCode(KeyEvent: TKeyEvent): TKeyEvent;
  111. begin
  112. TranslateKeyEventUniCode := KeyEvent;
  113. ErrorCode:=errKbdNotImplemented;
  114. end;
  115. end.
  116. {
  117. $Log$
  118. Revision 1.1 2001-01-13 11:03:57 peter
  119. * API 2 RTL commit
  120. }