예제 #1
0
  private void moveMouse(final int x, final int y) {
    // Firstly invoke drag events
    if (pressed) {
      final MouseEvent me =
          new MouseEvent(
              getTarget(), MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, x, y, 0, false);
      getClient().getMouse().sendEvent(me);
      if ((dragLength & 0xFF) != 0xFF) {
        dragLength++;
      }
    }

    if (!present) {
      if (InputManager.isOnCanvas(x, y)) { // Entered
        final MouseEvent me =
            new MouseEvent(
                getTarget(),
                MouseEvent.MOUSE_ENTERED,
                System.currentTimeMillis(),
                0,
                x,
                y,
                0,
                false);
        present = true;
        getClient().getMouse().sendEvent(me);
      } else return;
    }
    if (!InputManager.isOnCanvas(x, y)) {
      final MouseEvent me =
          new MouseEvent(
              getTarget(), MouseEvent.MOUSE_EXITED, System.currentTimeMillis(), 0, x, y, 0, false);
      present = false;
      getClient().getMouse().sendEvent(me);
      return;
    }
    if (!pressed) {
      final MouseEvent me =
          new MouseEvent(
              getTarget(), MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x, y, 0, false);
      getClient().getMouse().sendEvent(me);
    }
  }
예제 #2
0
  /**
   * 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));
    }
  }