tags:

views:

884

answers:

4

Hi !

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

A: 

If you're using Swing as your UI layer, you can use a Mouse-Motion Listener for this.

Andrzej Doyle
+4  A: 

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

Aviator
thank you, I think it's exactly what I needed
Martin Trigaux
A: 

Try looking at the java.awt.Robot class. It allows you to move the mouse programatically.

Jeff Storey
A: 

If you're using SWT, you might want to look at adding a MouseMoveListener as explained here.

Topher Fangio
but the Listener is executed only if I do something (move, click) with my mouse, right ? The first thing I need before moving it is to know the starting position
Martin Trigaux