/** * Drag the mouse from the current position to a certain other position. * * @param x the x coordinate to drag to * @param y the y coordinate to drag to */ public void dragMouse(final int x, final int y) { pressMouse(getX(), getY(), true); sleepNoException(random(300, 500)); windMouse(getX(), getY(), x, y); sleepNoException(random(300, 500)); releaseMouse(x, y, true); }
/** @see #windMouse(int, int, int, int, int) */ public void windMouse(final int curX, final int curY, final int targetX, final int targetY) { windMouse(MouseHandler.DEFAULT_MOUSE_SPEED, curX, curY, targetX, targetY); }
/** * Moves the mouse to the specified point at a certain sped. * * @param speed the lower, the faster. * @param x the x value * @param y the y value * @param randomX x-axis randomness (gets added to x) * @param randomY y-axis randomness (gets added to y) * @param MousePaths Whether or not to use Mouse Path generator */ public void moveMouse( final int speed, final int x, final int y, final int randomX, final int randomY, final boolean MousePaths) { int thisX = getX(), thisY = getY(); if (!InputManager.isOnCanvas(thisX, thisY)) { switch (random(1, 5)) { // on which side of canvas should it enter case 1: thisX = -1; thisY = random(0, CanvasWrapper.getGameHeight()); break; case 2: thisX = random(0, CanvasWrapper.getGameWidth()); thisY = CanvasWrapper.getGameHeight() + 1; break; case 3: thisX = CanvasWrapper.getGameWidth() + 1; thisY = random(0, CanvasWrapper.getGameHeight()); break; case 4: thisX = random(0, CanvasWrapper.getGameWidth()); thisY = -1; break; } } if (MousePaths) { final Point[] path = mouseHandler.generateMousePath( (int) Math.hypot(thisX - x, thisX - y) / 100 + random(1, 3), new Point(thisX, thisY), new Point(x, y)); if (path == null) { new Exception( "Mouse paths were enabled, and the path was returned null. Please report on forums: ") .printStackTrace(); } windMouse(speed, thisX, thisY, path[0].x, path[0].y); for (int i = 1; i < path.length; i++) { try { if (i == path.length - 1) { windMouse( speed, path[i - 1].x, path[i - 1].y, random(path[i].x, path[i].x + randomX), random(path[i].y, path[i].y + randomY)); } else { windMouse(speed, path[i - 1].x, path[i - 1].y, path[i].x, path[i].y); } } catch (final Exception e) { e.printStackTrace(); } } } else { windMouse(speed, thisX, thisY, random(x, x + randomX), random(y, y + randomY)); } }