저는 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));
}
}
}
"인간 답게"무엇을 의미합니까? – nebula
정확하게 직선으로 이동하지 마십시오. 어쩌면 몇 개의 픽셀이 여기 저기있을 수 있습니다. –
그런 다음 난수를 생성하고 그 수를 사용하여 직선을 변경하십시오. 그런 다음 로봇 클래스를 사용하십시오. – nebula