program KeyTest;{$A+,B-,E-,F-,G+,N+,O-,P+,T-,V-,X+}
{$D-,I-,L-,Q-,R-,S-,Y-}
{$M 65520,0,655360}
uses
 Dos;
var
 SaveKeyInterrupt:procedure;
 Key:Byte;
procedure KeyInterrupt;interrupt;
begin
 Key:=Port[96];
 inline($9C);{PUSHF----标志寄存器压栈}
 SaveKeyInterrupt;
end;
begin
 Key:=0;
 GetIntVec(9,@SaveKeyInterrupt);
 SetIntVec(9,@KeyInterrupt);
 WriteLn('Press ESC to exit');
 repeat
  if Key=1 then Break;
  if (Key>0)and(Key<128) then
  begin
   WriteLn('You pressed a key of ',Key);
   Key:=0;
  end;
  if Key>=128 then
  begin
   WriteLn('You unpressed a key of ',Key);
   Key:=0;
  end;
 until False;
 SetIntVec(9,@SaveKeyInterrupt);
end.