kbdbdump.pp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. { Keyboard BIOS dump tool. Dumps all keys and shift states using BIOS Int 16h
  2. function calls. This tool runs in DOS only. }
  3. program kbdbdump;
  4. {$MODE objfpc}{$H+}
  5. uses
  6. Video, Mouse, kbdutil, vidutil, Dos;
  7. procedure ShowShiftState;
  8. function BitAttr(var W: Word; bit: Integer): Byte;
  9. begin
  10. if (W and (1 shl bit)) <> 0 then
  11. BitAttr := $70
  12. else
  13. BitAttr := $07;
  14. end;
  15. var
  16. Regs: Registers;
  17. begin
  18. Regs.AH := $12; { get extended shift states }
  19. Intr($16, Regs);
  20. TextOut( 1, 16, 'SysReq', BitAttr(Regs.AX, 15));
  21. TextOut( 8, 16, 'Caps_Lock', BitAttr(Regs.AX, 14));
  22. TextOut(18, 16, 'Num_Lock', BitAttr(Regs.AX, 13));
  23. TextOut(27, 16, 'Scroll_Lock', BitAttr(Regs.AX, 12));
  24. TextOut(39, 16, 'Right_Alt', BitAttr(Regs.AX, 11));
  25. TextOut(49, 16, 'Right_Ctrl', BitAttr(Regs.AX, 10));
  26. TextOut(60, 16, 'Left_Alt', BitAttr(Regs.AX, 9));
  27. TextOut(69, 16, 'Left_Ctrl', BitAttr(Regs.AX, 8));
  28. TextOut( 1, 17, 'Insert', BitAttr(Regs.AX, 7));
  29. TextOut( 8, 17, 'CapsLock', BitAttr(Regs.AX, 6));
  30. TextOut(17, 17, 'NumLock', BitAttr(Regs.AX, 5));
  31. TextOut(25, 17, 'ScrollLock', BitAttr(Regs.AX, 4));
  32. TextOut(36, 17, 'Alt', BitAttr(Regs.AX, 3));
  33. TextOut(40, 17, 'Ctrl', BitAttr(Regs.AX, 2));
  34. TextOut(45, 17, 'Left_Shift', BitAttr(Regs.AX, 1));
  35. TextOut(56, 17, 'Right_Shift', BitAttr(Regs.AX, 0));
  36. end;
  37. procedure SampleAllKeys(const Kbd: TKeyboard; const OutFileName: AnsiString);
  38. var
  39. I: Integer;
  40. Regs: Registers;
  41. M: TMouseEvent;
  42. OutF: TextFile;
  43. begin
  44. AssignFile(OutF, OutFileName);
  45. Rewrite(OutF);
  46. for I := Low(kbd.Keys) to High(kbd.Keys) do
  47. begin
  48. DrawKey(kbd.Keys[I], $17);
  49. UpdateScreen(False);
  50. repeat
  51. ShowShiftState;
  52. UpdateScreen(False);
  53. Regs.AH := $11; { check for enhanced keystroke }
  54. Intr($16, Regs);
  55. if PollMouseEvent(M) then
  56. GetMouseEvent(M);
  57. until ((fZero and Regs.Flags) = 0) or ((GetMouseButtons and MouseRightButton) <> 0);
  58. if ((fZero and Regs.Flags) = 0) then
  59. begin
  60. Regs.AH := $10; { get enhanced keystroke }
  61. Intr($16, Regs);
  62. Write(OutF, Regs.AX, ' ');
  63. Regs.AH := $12; { get extended shift states }
  64. Intr($16, Regs);
  65. Writeln(OutF, Regs.AX);
  66. end
  67. else
  68. begin
  69. Writeln(OutF, '-1 -1');
  70. while (GetMouseButtons and MouseRightButton) <> 0 do
  71. begin
  72. if PollMouseEvent(M) then
  73. GetMouseEvent(M);
  74. end;
  75. end;
  76. DrawKey(kbd.Keys[I], $70);
  77. UpdateScreen(False);
  78. end;
  79. CloseFile(OutF);
  80. end;
  81. var
  82. kbd: TKeyboard;
  83. begin
  84. if ParamCount <> 2 then
  85. begin
  86. Writeln('Usage: ', ParamStr(0), ' <kbd_file> <output_file>');
  87. Halt(1);
  88. end;
  89. InitVideo;
  90. InitMouse;
  91. kbd := ReadKeyboardFromFile(ParamStr(1));
  92. DrawKeyboard(kbd);
  93. UpdateScreen(False);
  94. TextOut(1, 20, 'Press the highlighted key. Use the right mouse button to skip if the key', $07);
  95. TextOut(1, 21, 'cannot be detected.', $07);
  96. UpdateScreen(False);
  97. SampleAllKeys(kbd, ParamStr(2));
  98. DoneMouse;
  99. DoneVideo;
  100. end.