title: Making mouse movements humanlike (using an arc rather than a straight line to the destination)
body: <p>I am making and auto clicker using java.awt.Robot. One of the concerns i have however is the movements aren't very humanlike. Can anyone suggest some changes to my code to make it more human like? Right now it just moves in a straight line.</p>
  
  <pre><code>/**
   * 
   * @param robot The java.awt.Robot being utilized
   * @param sx The start x position of the mouse
   * @param sy The start y potition of the mouse
   * @param ex The end x position of the mouse
   * @param ey The end y position of the mouse
   * @param speed The speed at which to travel
   */
  public void moveMouse(Robot robot, int sx, int sy, int ex, int ey, int speed){
      for (int i=0; i&lt;100; i++){  
          int mov_x = ((ex * i)/100) + (sx*(100-i)/100);
          int mov_y = ((ey * i)/100) + (sy*(100-i)/100);
          robot.mouseMove(mov_x,mov_y);
          robot.delay(speed);
      }
  
  }
  </code></pre>
  
  <p><strong>Update:</strong>
  I decided to go with an algorithm that makes use of <a href="https://en.wikipedia.org/wiki/B%C3%A9zier_curve" rel="nofollow">Bézier Curves</a>. It's been a very long time since I implemented the change, but I wanted to post it here just in case people would find it useful in the future. Here is what I ended up with:</p>
  
  <pre><code>public class MouseEvent{
      public int getMouseX(){
          return MouseInfo.getPointerInfo().getLocation().x;
      }
  
      public int getMouseY(){
          return MouseInfo.getPointerInfo().getLocation().y;
      }
  
      public void moveMouse(int speed, int destX, int destY, int ranX, int ranY){
          Mouse.moveMouse(new Robot(), new Point(getMouseX(),getMouseY()), new Point(destX, destY), speed, ranX, ranY);
      }
  }
  
  public class Mouse {
      public static void moveMouse(Robot robot, Point s, Point e, int speed, int ranX, int ranY){
          if(Math.abs(e.x-s.x) &lt;= ranX &amp;&amp; Math.abs(e.y-s.y) &lt;= ranY)
              return;
  
          Point[] cooardList;
          double t;    //the time interval
          double k = .025;
          cooardList = new Point[4];
  
          //set the beginning and end points
          cooardList[0] = s;
          cooardList[3] = new Point(e.x+random(-ranX,ranX),e.y+(random(-ranY,ranY)));
  
          int xout = (int)(Math.abs(e.x - s.x) /10);
          int yout = (int)(Math.abs(e.y - s.y) /10);
  
          int x=0,y=0;
  
          x = s.x &lt; e.x 
              ? s.x + ((xout &gt; 0) ? random(1,xout) : 1)
              : s.x - ((xout &gt; 0) ? random(1,xout) : 1);
          y = s.y &lt; e.y 
              ? s.y + ((yout &gt; 0) ? random(1,yout) : 1)
              : s.y - ((yout &gt; 0) ? random(1,yout) : 1);
          cooardList[1] = new Point(x,y);
  
          x = e.x &lt; s.x 
              ? e.x + ((xout &gt; 0) ? random(1,xout) : 1)
              : e.x - ((xout &gt; 0) ? random(1,xout) : 1);
          y = e.y &lt; s.y 
              ?  e.y + ((yout &gt; 0) ? random(1,yout) : 1)
              : e.y - ((yout &gt; 0) ? random(1,yout) : 1);
          cooardList[2] = new Point(x,y);
  
          double px = 0,py = 0;
          for(t=k;t&lt;=1+k;t+=k){
              //use Berstein polynomials
              px=(cooardList[0].x+t*(-cooardList[0].x*3+t*(3*cooardList[0].x-
                  cooardList[0].x*t)))+t*(3*cooardList[1].x+t*(-6*cooardList[1].x+
                  cooardList[1].x*3*t))+t*t*(cooardList[2].x*3-cooardList[2].x*3*t)+
                  cooardList[3].x*t*t*t;
              py=(cooardList[0].y+t*(-cooardList[0].y*3+t*(3*cooardList[0].y-
                  cooardList[0].y*t)))+t*(3*cooardList[1].y+t*(-6*cooardList[1].y+
                  cooardList[1].y*3*t))+t*t*(cooardList[2].y*3-cooardList[2].y*3*t)+
                  cooardList[3].y*t*t*t;
              robot.mouseMove((int)px, (int)py);
              robot.delay(random(speed,speed*2));
          }
      }    
  }
  </code></pre>