Get Mouse Position

Martin Trigaux picture Martin Trigaux · Sep 17, 2009 · Viewed 245.3k times · Source

I would like to simulate a natural mouse movement in Java (going from here to there pixel by pixel). To do that I need to know the starting coordinates.

I've found the method event.getX() and event.getY() but I need an event...

How can I know the positions without doing anything (or something not visible)?

Thank you

Answer

vpram86 picture vpram86 · Sep 17, 2009

MouseInfo.getPointerInfo().getLocation() might be helpful. It returns a Point object corresponding to current mouse position.