kbddump.pp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. program kbddump;
  2. {$MODE objfpc}{$H+}
  3. uses
  4. Video, Keyboard, Mouse, kbdutil, vidutil;
  5. procedure SampleAllKeys(const Kbd: TKeyboard; const OutFileName: AnsiString);
  6. var
  7. I: Integer;
  8. K: TKeyEvent;
  9. M: TMouseEvent;
  10. OutF: TextFile;
  11. begin
  12. AssignFile(OutF, OutFileName);
  13. Rewrite(OutF);
  14. for I := Low(kbd.Keys) to High(kbd.Keys) do
  15. begin
  16. DrawKey(kbd.Keys[I], $17);
  17. UpdateScreen(False);
  18. repeat
  19. K := PollKeyEvent;
  20. if PollMouseEvent(M) then
  21. GetMouseEvent(M);
  22. until (K <> 0) or ((GetMouseButtons and MouseRightButton) <> 0);
  23. if K <> 0 then
  24. begin
  25. K := GetKeyEvent;
  26. Write(OutF, K, ' ');
  27. K:=TranslateKeyEvent(K);
  28. Writeln(OutF, K);
  29. end
  30. else
  31. begin
  32. Writeln(OutF, '-1 -1');
  33. while (GetMouseButtons and MouseRightButton) <> 0 do
  34. begin
  35. if PollMouseEvent(M) then
  36. GetMouseEvent(M);
  37. end;
  38. end;
  39. DrawKey(kbd.Keys[I], $70);
  40. UpdateScreen(False);
  41. end;
  42. CloseFile(OutF);
  43. end;
  44. var
  45. kbd: TKeyboard;
  46. begin
  47. if ParamCount <> 2 then
  48. begin
  49. Writeln('Usage: ', ParamStr(0), ' <kbd_file> <output_file>');
  50. Halt(1);
  51. end;
  52. InitVideo;
  53. InitKeyboard;
  54. InitMouse;
  55. kbd := ReadKeyboardFromFile(ParamStr(1));
  56. DrawKeyboard(kbd);
  57. UpdateScreen(False);
  58. TextOut(1, 20, 'Press the highlighted key. Use the right mouse button to skip if the key', $07);
  59. TextOut(1, 21, 'cannot be detected.', $07);
  60. UpdateScreen(False);
  61. SampleAllKeys(kbd, ParamStr(2));
  62. DoneMouse;
  63. DoneKeyboard;
  64. DoneVideo;
  65. end.