kbd.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. Constructor TDosKeyboard.Create;
  2. Begin
  3. { defaults }
  4. m_key := False;
  5. m_head := 0;
  6. m_tail := 0;
  7. End;
  8. Destructor TDosKeyboard.Destroy;
  9. Begin
  10. Inherited Destroy;
  11. End;
  12. Procedure TDosKeyboard.internal_ReadKey(k : TPTCKey);
  13. Var
  14. read : TPTCKey;
  15. Begin
  16. While Not ready Do;
  17. read := remove;
  18. Try
  19. k.ASSign(read);
  20. Finally
  21. read.Free;
  22. End;
  23. End;
  24. Function TDosKeyboard.internal_PeekKey(k : TPTCKey) : Boolean;
  25. Begin
  26. Result := ready;
  27. If Result = True Then
  28. k.ASSign(m_buffer[m_tail]);
  29. End;
  30. Procedure TDosKeyboard.insert(_key : TPTCKey);
  31. Begin
  32. { check for overflow }
  33. If (m_head <> (m_tail - 1)) And
  34. ((m_tail <> 0) Or (m_head <> High(m_buffer))) Then
  35. Begin
  36. { insert key at head }
  37. m_buffer[m_head] := _key;
  38. { increase head }
  39. Inc(m_head);
  40. { wrap head from end to start }
  41. If m_head > High(m_buffer) Then
  42. m_head := Low(m_buffer);
  43. End;
  44. End;
  45. Function TDosKeyboard.remove : TPTCKey;
  46. Begin
  47. { return key data from tail }
  48. remove := m_buffer[m_tail];
  49. { increase tail }
  50. Inc(m_tail);
  51. { wrap tail from end to start }
  52. If m_tail > High(m_buffer) Then
  53. m_tail := Low(m_buffer);
  54. End;
  55. Function TDosKeyboard.ready : Boolean;
  56. Var
  57. c : Integer;
  58. Ch, Ex : Char;
  59. Begin
  60. If KeyPressed Then
  61. Begin
  62. Ch := ReadKey;
  63. If Ch = #0 Then
  64. Ex := ReadKey
  65. Else
  66. Ex := #0;
  67. If Ch <> #0 Then
  68. Begin
  69. Ch := UpCase(Ch);
  70. c := Ord(Ch);
  71. End
  72. Else
  73. Begin
  74. Case Ord(Ex) Of
  75. 59 : c := PTCKEY_F1;
  76. 60 : c := PTCKEY_F2;
  77. 61 : c := PTCKEY_F3;
  78. 62 : c := PTCKEY_F4;
  79. 63 : c := PTCKEY_F5;
  80. 64 : c := PTCKEY_F6;
  81. 65 : c := PTCKEY_F7;
  82. 66 : c := PTCKEY_F8;
  83. 67 : c := PTCKEY_F9;
  84. 68 : c := PTCKEY_F10;
  85. 71 : c := PTCKEY_HOME;
  86. 72 : c := PTCKEY_UP;
  87. 73 : c := PTCKEY_PAGEUP;
  88. 75 : c := PTCKEY_LEFT;
  89. 76 : c := PTCKEY_NUMPAD5;
  90. 77 : c := PTCKEY_RIGHT;
  91. 79 : c := PTCKEY_END;
  92. 80 : c := PTCKEY_DOWN;
  93. 81 : c := PTCKEY_PAGEDOWN;
  94. 82 : c := PTCKEY_INSERT;
  95. 83 : c := PTCKEY_DELETE;
  96. 133 : c := PTCKEY_F11;
  97. 134 : c := PTCKEY_F12;
  98. End;
  99. End;
  100. insert(TPTCKey.Create(c, False, False, False, True));
  101. insert(TPTCKey.Create(c, False, False, False, False));
  102. End;
  103. ready := m_head <> m_tail;
  104. End;