2011-12-16 2 views
2

저는 java.awt.Robot을 사용하여 자동 크리커를 만들고 있습니다. 그러나 내가 가지고있는 관심사 중 하나는 움직임이 아주 인간답지 않다는 것입니다. 누구든지 더 많은 인간을 만들기 위해 코드에 몇 가지 변경 사항을 제안 할 수 있습니까? 지금은 그냥 직선으로 움직입니다.마우스 움직임을 인간 답게 만들기 (대상에 직선이 아닌 호를 사용)

/** 
* 
* @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<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); 
    } 

} 

업데이트 : Bézier Curves의 사용을 만드는 알고리즘으로 가기로 결정 . 변화를 실행 한 지 꽤 오랜 시간이 걸렸지 만 사람들이 미래에 유용하다고 생각한 경우를 대비하여 여기에 게시하고 싶었습니다. 다음은 내가 끝난 결과입니다.

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) <= ranX && Math.abs(e.y-s.y) <= 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 < e.x 
      ? s.x + ((xout > 0) ? random(1,xout) : 1) 
      : s.x - ((xout > 0) ? random(1,xout) : 1); 
     y = s.y < e.y 
      ? s.y + ((yout > 0) ? random(1,yout) : 1) 
      : s.y - ((yout > 0) ? random(1,yout) : 1); 
     cooardList[1] = new Point(x,y); 

     x = e.x < s.x 
      ? e.x + ((xout > 0) ? random(1,xout) : 1) 
      : e.x - ((xout > 0) ? random(1,xout) : 1); 
     y = e.y < s.y 
      ? e.y + ((yout > 0) ? random(1,yout) : 1) 
      : e.y - ((yout > 0) ? random(1,yout) : 1); 
     cooardList[2] = new Point(x,y); 

     double px = 0,py = 0; 
     for(t=k;t<=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)); 
     } 
    }  
} 
+0

"인간 답게"무엇을 의미합니까? – nebula

+0

정확하게 직선으로 이동하지 마십시오. 어쩌면 몇 개의 픽셀이 여기 저기있을 수 있습니다. –

+0

그런 다음 난수를 생성하고 그 수를 사용하여 직선을 변경하십시오. 그런 다음 로봇 클래스를 사용하십시오. – nebula

답변

1

Catmull-Rom 방식을 사용할 수 있습니다. 끝점 주위 어딘가에 임의의 제어점을 생성하고 직선이 어디에 있는지, 시작부터 끝까지 모든 단계에서 좌표를 요구합니다 (매개 변수 t, 0에서 1로).

참조 데모 애플릿 및 소스 : http://www.cse.unsw.edu.au/~lambert/splines/

1
public void moveMouse(int sx, int sy, int ex, int ey, int speed) throws AWTException { 
     Robot robot = new Robot(); 
     int a = 10; 
     boolean flag = true; 
     for (int i = 0; i < 100; i++) { 
      int mov_x = ((ex * i)/100) + (sx * (100 - i)/100); 
      int mov_y = ((ey * i)/100) + (sy * (100 - i)/100); 
      if (flag == true) { 
       robot.mouseMove(mov_x + a, mov_y); // adds 10 to X-axis 
       flag = false; 
      } else { 
       robot.mouseMove(mov_x - 2 * a, mov_y); // subtracts 20 to X-axis 
       flag = true; 
      } 
      robot.delay(speed); 
     } 
    } 

그냥 코드를 조작. 이렇게하면 마우스가 X 방향으로 직선 경로로 이동합니다. 여기서 원하는 것을 얻을 수 있습니다. 아이디어를 얻으십시오. mov_xmov_y을 조작 할 수 있다면 원하는 방향으로 이동할 수 있습니다.

+0

잘못된 부분이 있으면 바로 잡으십시오. 그러나 무엇을 보지 못합니다. 당신은 끝점이 목표 목적지가 될 수 있도록 추가했습니다. 또한,이 모든 것은 지그재그입니다. = 1을 변경하더라도, 마우스는 여전히 빠르게 흔들립니다. –

+0

moveMouse()에서 무엇을 전달 했습니까? 나는 moveMouse (303030500100)를 시도했다. 그리고 나는 원호가 인간 같은 것이 아니라는 것을 의미한다고 생각합니다. – nebula

+0

그런데 원, 선 또는 임의의 유형의 임의의 커브를 생성하려는 경우 (원어에서와 같이) 먼저 원, 선 또는 곡선 그리기 알고리즘을 알고 임의성을 생성하기 위해 조작해야합니다. http://stackoverflow.com/questions/6641977/how-to-create-a-curve-between-2-points-in-2d-and-get-back-points-that-makes-that – nebula

관련 문제