Egérkezelés - példaprogram

program Eger;
uses Graph, Dos, Crt;
var gd, gm, i, j: integer;
    x, y, x1, y1, x2, y2: word;
    r: registers;

procedure Init;
  begin
    r.ax := 0;
    Intr($33, r);
  end;

procedure Be;
  begin
    r.ax := 1;
    Intr($33, r);
  end;

procedure Ki;
  begin
    r.ax := 2;
    Intr($33, r);
  end;

function LeBal: boolean;
  begin
    r.ax := 3;
    Intr($33, r);
    LeBal := r.bx=1;
  end;

function LeJobb: boolean;
  begin
    r.ax := 3;
    Intr($33, r);
    LeJobb := r.bx=2;
  end;

function XKoor: integer;
  begin
    r.ax := 3;
    Intr($33, r);
    XKoor := r.cx;
  end;

function YKoor: integer;
  begin
    r.ax := 3;
    Intr($33, r);
    YKoor := r.dx;
  end;

begin
  gd := detect;
  InitGraph(gd, gm, 'c:\bp\bgi');
  Init;
  Be;
  {Vonalhuzás}
  repeat
    repeat until LeBal or LeJobb;  {Várakozás}
    Ki;                            {Rajzolás közben az egér kikapcsolása}
    MoveTo(XKoor, YKoor);          {Rajzolás}
    repeat
      LineTo(XKoor, YKoor)
    until not LeBal;               {Rajzolás vége}
    Be;
  until LeJobb;                    {Vonalhúzás vége}

  Delay(500);
  {Téglalapok rajzolása}
  SetWriteMode(xorput);
  repeat
    repeat  until LeBal or LeJobb;
    Ki;
    x1 := XKoor; y1:= YKoor;
    x2 := XKoor; y2 := YKoor;
    repeat
      if (XKoor <> x2) or (YKoor <> y2) then
        begin
         Rectangle(x1, y1, x2, y2);
         x2 := XKoor; y2 := YKoor;
         Rectangle(x1, y1, x2, y2)
        end
    until not LeBal;
    Be;
  until Lejobb;

end.