title: SetCursorPos malfunctions?
body: <p>I wanted to write a procedure in delphi to simulate a moving mouse pointer with a specific speed (similar to the AutoIT MouseMove function).
  Either my code is wrong or SetCursorPos malfunctions after it gets called too many times.
  Here is the function I have:</p>
  
  <pre><code>procedure MoveMouse ( X, Y, Speed : Integer);
  var
    P     : TPoint;
    NewX  : Integer;
    NewY  : Integer;
  begin
    if X &lt; 0 then exit;
    if Y &lt; 0 then exit;
    if X &gt; Screen.Height then exit;
    if Y &gt; Screen.Width then Exit;
    repeat
      GetCursorPos(P);
      NewX := P.X;
      NewY := P.Y;
      if P.X &lt;&gt; X then begin
        if P.X &gt; X then begin
          NewX := P.X - 1;
        end else begin
          NewX := P.X + 1;
        end;
      end;
      if P.Y &lt;&gt; Y then begin
        if P.Y &gt; Y then begin
          NewY := P.Y - 1;
        end else begin
          NewY := P.Y + 1;
        end;
      end;
      sleep (Speed);
      SetCursorPos(NewX, NewY);
    until (P.X = X) and (P.Y = Y);
  end;
  </code></pre>
  
  <p>I use it like this:</p>
  
  <pre><code>procedure TForm1.btn1Click(Sender: TObject);
  var
    X : Integer;
    Y : Integer;
  begin
    for X := 0 to Screen.Width do begin
      for Y := 0 to Screen.Height do begin
        MouseClick (X, Y, 1);
      end;
    end;
  end;
  </code></pre>
  
  <p>For some reason the mousepointer gets stuck at a certain X point and then jumps back to 0,0 but why is that?</p>