3

Is there anyway to do a mousemove event with java.awt.Component.dispatchEvent(AWTEvent)?

.dispatchEvent(new MouseEvent(client.a
                           .getComponentAt(1, 1),
                               MouseEvent.MOUSE_MOVED,
                               System.currentTimeMillis(),
                               MouseEvent.NOBUTTON,
                               x,y,
                               1,
                               false));

I got this now but it doesnt perform a mouse move. How can i do it?

Edit: I tried it like this but its not working:

.dispatchEvent(new MouseEvent(client.a
                           .getComponentAt(1, 1),
                               MouseEvent.MOUSE_MOVED,
                               System.currentTimeMillis(),
                               MouseEvent.NOBUTTON,
                               x,y,
                               0,
                               false));

Thanks, Jeffrey

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
  • I know of no way to do this the way you're trying as the MouseEvent (as far as I understand it) is for sending mouse messages to components not the operating system. Usually I've used the Robot class or [JNA](http://en.wikipedia.org/wiki/Java_Native_Access) to actually move the mouse cursor on the screen. – Hovercraft Full Of Eels Feb 03 '12 at 17:12
  • Do you want your component to react on a MouseEvent which did not actually happened (faking mouse events), or do you want to move the cursor on the screen ? – Robin Feb 03 '12 at 17:15
  • Like a virtual mouse. On a applet. – Jeffrey Barneveld Feb 03 '12 at 18:00
  • @JeffreyGearsoffun: answer given in comment. If you want it official, I'll make it an "answer". – Hovercraft Full Of Eels Feb 03 '12 at 18:10

2 Answers2

4

I use Abbot to emulate MouseEvent in my application. It was recently updated by an Oracle employee for Java 6, JUnit 4, etc.

Rhangaun
  • 1,430
  • 2
  • 15
  • 34
3

I know of no way to do this the way you're trying as the MouseEvent (as far as I understand it) is for sending mouse messages to components not the operating system. Usually I've used the Robot class or JNA to actually move the mouse cursor on the screen.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373