program AvoidHangs2(keyboard, output);
import uio,sysdevs;
const
  TimeLimit=            200;                    {200 centiseconds = 2 seconds}
var
  keyboard:             text;
  Character:            char;
  Start:                integer;
  GotOne:               boolean;
begin
writeln(output,'Press any key within two seconds!');
Start:=sysclock;
GotOne:=false;
repeat
  if not unitbusy(2) then                {"busy" means typeahead buffer empty}
    begin
    writeln(output,'You beat me!');
    read(keyboard, Character);     {eat the character in the typeahead buffer}
    GotOne:=true;
    end;
until GotOne or (sysclock>(Start+TimeLimit));
if not GotOne then
  writeln(output,#G,'Wow, you ARE slow!');
end.
