79280597

Date: 2024-12-14 12:13:57
Score: 0.5
Natty:
Report link

Thanks to gthanop's answer I was able to figure out a solution to the issue. Here is the updated code

// Add a mouse listener
c.addMouseMotionListener(new MouseAdapter() {
    // If the mouse is moved
    public void mouseMoved(MouseEvent e) {
        // Get the current X
        int currentX = e.getX();
        // Get the current Y
        int currentY = e.getY();
                
        // Get the current X on screen
        int currentXOnScreen = f.getX() + currentX;
        // Get the current Y on screen
        int currentYOnScreen = f.getY() + currentY;
                
        // Get the mouse X position delta
        infiniteMouse.x += (currentXOnScreen - infiniteMouse.centerX) + 8;
        // Get the mouse Y position delta
        infiniteMouse.y += (currentYOnScreen - infiniteMouse.centerY) + 8;
                
        // Move the mouse to the center
        robot.mouseMove(infiniteMouse.centerX, infiniteMouse.centerY);
    }
});

I believe that Robot.moveMouse infact does not move the pointer to the specified location but sets the center of the pointer to the specified location. That is why I add 8 to the difference. However I am not sure as to what the reason could be but since it works I will just leave it like that.

This answer provides a solution to the problem in the question. However gthanop's answer provides a lot more detail I highly recommend reading that

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Bob the Builder