I am trying to simulate real mouse clicks without moving the cursor with javas robot class. Is it possible putting this code in a while-loop or something to register the mouse position, and move the mouse to that position after the actual click? so far the code is told to move the mouse to the registered mouse position (it registers once I run the code) but I want it to move the mouse to the same position as my mouse is on, not somewhere in the corner. Thank you.
while(true) { PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); int xOrig = (int)b.getX(); int yOrig = (int)b.getY(); try { Robot r = new Robot(); Thread.sleep(3000); r.mouseMove(720, 360); r.mousePress(InputEvent.BUTTON1_MASK); //press the left mouse button r.mouseRelease(InputEvent.BUTTON1_MASK); //release the left mouse button //move the mouse back to the original position r.mouseMove(xOrig, yOrig); } catch (Exception e) { System.out.println(e.toString()); } } } }