Eksempel:
program SkipKeys;
uses
Classes, SysUtils, Windows, Crt;
type
Skipper = class(TThread)
protected
procedure Execute; override;
end;
var
done : boolean;
procedure Skipper.Execute;
begin
while not done do begin
if KeyPressed then begin
ReadKey;
end else begin
Sleep(10);
end;
end;
end;
var
skipt : Skipper;
procedure StartBlock;
begin
done := false;
skipt := Skipper.Create(true);
skipt.Start;
end;
procedure StopBlock;
begin
done := true;
skipt.WaitFor;
skipt.Terminate;
skipt.Free;
end;
begin
StartBlock;
writeln('Enter something');
Sleep(5000);
StopBlock;
writeln('Enter something again');
writeln('You entered: ' + ReadKey);
end.
Jeg vil stadig ikke udelukke at en mere elegant løsning eksisterer, men det var hvad jeg lige kunne komme op med.
NB: done bør erklæres volatile, men det er ikke understøttet i min version af FPC.