kbdtest.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. program KbdTest;
  2. {$MODE objfpc}{$H+}
  3. uses
  4. Video, Keyboard, Mouse, kbdutil, vidutil;
  5. const
  6. LastPressedAttr = $E0;
  7. PreviouslyPressedAttr = $0F;
  8. NotPressedAttr = $6F;
  9. NotAvailableAttr = $08;
  10. var
  11. kbd: TKeyboard;
  12. KbdEventMap: array of array [0..1] of TKeyEvent;
  13. KeyHasBeenPressed: array of Boolean;
  14. DumpF: TextFile;
  15. I: Integer;
  16. a1, a2: Int64;
  17. K, TK: TKeyEvent;
  18. M: TMouseEvent;
  19. FoundKey: Boolean;
  20. begin
  21. if ParamCount <> 2 then
  22. begin
  23. Writeln('Usage: ', ParamStr(0), ' <kbd_file> <dump_file>');
  24. Halt(1);
  25. end;
  26. InitVideo;
  27. InitKeyboard;
  28. InitMouse;
  29. kbd := ReadKeyboardFromFile(ParamStr(1));
  30. SetLength(KbdEventMap, Length(kbd.Keys));
  31. SetLength(KeyHasBeenPressed, Length(kbd.Keys));
  32. AssignFile(DumpF, ParamStr(2));
  33. Reset(DumpF);
  34. for I := Low(kbd.Keys) to High(kbd.Keys) do
  35. begin
  36. KeyHasBeenPressed[I] := False;
  37. Readln(DumpF, a1, a2);
  38. if (a1 = -1) or (a2 = -1) then
  39. begin
  40. KbdEventMap[I][0] := 0;
  41. KbdEventMap[I][1] := 0;
  42. DrawKey(kbd.Keys[I], NotAvailableAttr);
  43. end
  44. else
  45. begin
  46. KbdEventMap[I][0] := a1;
  47. KbdEventMap[I][1] := a2;
  48. DrawKey(kbd.Keys[I], NotPressedAttr);
  49. end;
  50. end;
  51. CloseFile(DumpF);
  52. TextOut(1, 20, 'Press each of the highlighted keys.', $07);
  53. TextOut(1, 21, 'Click the right mouse button to exit.', $07);
  54. UpdateScreen(False);
  55. repeat
  56. repeat
  57. K := PollKeyEvent;
  58. if PollMouseEvent(M) then
  59. GetMouseEvent(M);
  60. until (K <> 0) or ((GetMouseButtons and MouseRightButton) <> 0);
  61. if K <> 0 then
  62. begin
  63. K := GetKeyEvent;
  64. TK := TranslateKeyEvent(K);
  65. FoundKey := False;
  66. for I := Low(kbd.Keys) to High(kbd.Keys) do
  67. if (KbdEventMap[I][0] = K) and (KbdEventMap[I][1] = TK) then
  68. begin
  69. FoundKey := True;
  70. KeyHasBeenPressed[I] := True;
  71. DrawKey(kbd.Keys[I], LastPressedAttr);
  72. end
  73. else if KeyHasBeenPressed[I] then
  74. DrawKey(kbd.Keys[I], PreviouslyPressedAttr)
  75. else if KbdEventMap[I][0] <> 0 then
  76. DrawKey(kbd.Keys[I], NotPressedAttr)
  77. else
  78. DrawKey(kbd.Keys[I], NotAvailableAttr);
  79. if not FoundKey then
  80. begin
  81. TextOut(1, 18, 'Unknown key code.', $04);
  82. end;
  83. UpdateScreen(False);
  84. end;
  85. until (GetMouseButtons and MouseRightButton) <> 0;
  86. DoneMouse;
  87. DoneKeyboard;
  88. DoneVideo;
  89. end.