3

I am attempting to send native MouseEvents and KeyEvents to a java application.

I've figured out how to do it in AWT, like this:

KeyEvent k = new KeyEvent(j, KeyEvent.KEY_TYPED, 1, 0, KeyEvent.VK_UNDEFINED, 'k');
j.requestFocus();
java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(k);

Where j is your component.

The thing is though, this only works on Java/AWT components. I'm attempting to emulate a mouse press or key press in DJ Native Browser, but it doesn't work here, possibly because this browser doesn't use AWT. Is there a way I can send a native windows event to the application without affecting my actual keyboard and mouse? Obviously awt.Robot is the obvious answer but it DOES affect the windows mouse and keyboard.

If the way to do it is operating-system dependent, that is OK. As long as it works on windows 64 bit, there is no issue with that.

Another possibility would be a java swing browser that runs on AWT, but I have yet to find a working, up-to-date browser besides DJNative, let alone one that runs on AWT.

Suggestions??

Thanks

Nathan
  • 1,287
  • 6
  • 15
  • 32
  • Unfortunately, you're still on the wrong side of the fence. That is, the SystemEventQueue is a Java based event queue, which is used to take system events from the OS and translate them to Java events. You may need to investigate a JNI/JNA solution to inject new events into the OS level event queue. There a number of issues related to doing this (needing the window handle for the target window for example), but it's probably the best choice you've got left.... – MadProgrammer Jul 18 '14 at 02:50
  • @MadProgrammer , perhaps I should try to find an AWT browser then? In standard swing components, the above code works fine and I can emulate keypresses and mouse actions fine. – Nathan Jul 18 '14 at 02:56
  • I don't know of any standard component that is up to the modern WebKit implementations – MadProgrammer Jul 18 '14 at 03:02
  • Do some research into WebKit, which what most of the modern browsers are now built upon. Have a look at http://lobobrowser.org/java-browser.jsp, https://code.google.com/p/flying-saucer/ and maybe https://weblogs.java.net/blog/ixmal/archive/2008/05/introducing_jwe.html but it seems to be dated – MadProgrammer Jul 18 '14 at 03:11
  • @Nathan: Please have a look at this [thread](http://stackoverflow.com/q/14118734/1057230), might be, it will be of some importance in your endeavour :-) – nIcE cOw Jul 18 '14 at 04:57
  • Thank you both of you, your comments gave me a few leads for where to look, back go research! – Nathan Jul 18 '14 at 14:29

0 Answers0