+ added an interactive keyboard test

git-svn-id: branches/unicodekvm@40228 -
This commit is contained in:
nickysn 2018-11-05 15:04:36 +00:00
parent f964dacd24
commit 12e66de0a6
2 changed files with 101 additions and 0 deletions

1
.gitattributes vendored
View File

@ -7423,6 +7423,7 @@ packages/rtl-console/src/win16/mouse.pp svneol=native#text/plain
packages/rtl-console/src/win16/video.pp svneol=native#text/plain
packages/rtl-console/tests/kbd1.pp svneol=native#text/plain
packages/rtl-console/tests/kbddump.pp svneol=native#text/plain
packages/rtl-console/tests/kbdtest.pp svneol=native#text/plain
packages/rtl-console/tests/kbdutil.pp svneol=native#text/plain
packages/rtl-console/tests/us101.txt svneol=native#text/plain
packages/rtl-console/tests/vidutil.pp svneol=native#text/plain

View File

@ -0,0 +1,100 @@
program KbdTest;
{$MODE objfpc}{$H+}
uses
Video, Keyboard, Mouse, kbdutil, vidutil;
const
LastPressedAttr = $E0;
PreviouslyPressedAttr = $0F;
NotPressedAttr = $6F;
NotAvailableAttr = $08;
var
kbd: TKeyboard;
KbdEventMap: array of array [0..1] of TKeyEvent;
KeyHasBeenPressed: array of Boolean;
DumpF: TextFile;
I: Integer;
a1, a2: Int64;
K, TK: TKeyEvent;
M: TMouseEvent;
FoundKey: Boolean;
begin
if ParamCount <> 2 then
begin
Writeln('Usage: ', ParamStr(0), ' <kbd_file> <dump_file>');
Halt(1);
end;
InitVideo;
InitKeyboard;
InitMouse;
kbd := ReadKeyboardFromFile(ParamStr(1));
SetLength(KbdEventMap, Length(kbd.Keys));
SetLength(KeyHasBeenPressed, Length(kbd.Keys));
AssignFile(DumpF, ParamStr(2));
Reset(DumpF);
for I := Low(kbd.Keys) to High(kbd.Keys) do
begin
KeyHasBeenPressed[I] := False;
Readln(DumpF, a1, a2);
if (a1 = -1) or (a2 = -1) then
begin
KbdEventMap[I][0] := 0;
KbdEventMap[I][1] := 0;
DrawKey(kbd.Keys[I], NotAvailableAttr);
end
else
begin
KbdEventMap[I][0] := a1;
KbdEventMap[I][1] := a2;
DrawKey(kbd.Keys[I], NotPressedAttr);
end;
end;
CloseFile(DumpF);
TextOut(1, 20, 'Press each of the highlighted keys.', $07);
TextOut(1, 21, 'Click the right mouse button to exit.', $07);
UpdateScreen(False);
repeat
repeat
K := PollKeyEvent;
if PollMouseEvent(M) then
GetMouseEvent(M);
until (K <> 0) or ((GetMouseButtons and MouseRightButton) <> 0);
if K <> 0 then
begin
K := GetKeyEvent;
TK := TranslateKeyEvent(K);
FoundKey := False;
for I := Low(kbd.Keys) to High(kbd.Keys) do
if (KbdEventMap[I][0] = K) and (KbdEventMap[I][1] = TK) then
begin
FoundKey := True;
KeyHasBeenPressed[I] := True;
DrawKey(kbd.Keys[I], LastPressedAttr);
end
else if KeyHasBeenPressed[I] then
DrawKey(kbd.Keys[I], PreviouslyPressedAttr)
else if KbdEventMap[I][0] <> 0 then
DrawKey(kbd.Keys[I], NotPressedAttr)
else
DrawKey(kbd.Keys[I], NotAvailableAttr);
if not FoundKey then
begin
TextOut(1, 18, 'Unknown key code.', $04);
end;
UpdateScreen(False);
end;
until (GetMouseButtons and MouseRightButton) <> 0;
DoneMouse;
DoneKeyboard;
DoneVideo;
end.