In Java, is it possible to use the Robot class to simulate keypresses to a Java window that is inactive (aka, that has been minimized to the background)?
-
I don't think this would be possible with Robot, however there may be a way by tapping into the windows API.Shaded– Shaded2011-03-02 16:04:31 +00:00Commented Mar 2, 2011 at 16:04
-
@Shaded, would that pretend to be native input just like Robot tries to do? Aka, would it be received in the same way as a normal key press for that application?Tom– Tom2011-03-02 16:08:08 +00:00Commented Mar 2, 2011 at 16:08
-
I think so, I've only recently started looking into using the windows API from a Java program. Take a look at Wikipedia you might be able to find some help there.Shaded– Shaded2011-03-02 16:25:02 +00:00Commented Mar 2, 2011 at 16:25
1 Answer
No, that's not possible.
Robot class is just a handle of the mouse and keyboard ( among others ) and doesn't have special privileges over another Java application ( the same way it doesn't have any privileges over a non java application )
If you need to do this and you have the source code of your application, you can add support for that application and listen external applications.
If you don't have the source code and still need this behavior another possibility ( depending on what you need to do ) is to install a virtual machine ( like VMWare ) and run the program there, and have that VM minimized.