Replicating MouseEvents

Viewed 39

I'm trying to replicate mouse events inside a applet, such as click based on x/y coords. I currently have a MouseListener implemented which records mouse movements, press, release etc but whenever I try to programmatically replicate mouse events such as Click at x/y the event is never triggered?

Example of a MouseEvent I've tried to replicate click at x/y:

applet.getComponent(0).dispatchEvent(new MouseEvent(applet,
                MouseEvent.MOUSE_PRESSED,
                System.currentTimeMillis() + 10,
                MouseEvent.BUTTON1,
               x,y,
                0,
                false));

        applet.getComponent(0).dispatchEvent(new MouseEvent(applet,
                MouseEvent.MOUSE_RELEASED,
                System.currentTimeMillis() + 10,
                MouseEvent.BUTTON1,
               x,y,
                0,
                false));

But nothing is registered.. I've searched through multiple stackoverflow posts and just can't seem to find the solution. There's another solution I found and that's using Java.awt.Robot but that takes control of system mouse, which I'm trying to avoid.

0 Answers
Related