views:

32

answers:

1

I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?

I have looked at java.awt.Robot, but it appears to hijack the mouse. I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.

Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.

+3  A: 

I recommend that automation via the GUI only as the last resort if you really have no other alternative.

If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.

If you really have no choice but to automate via the GUI, then here's how to go about doing that:

  1. Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
  2. Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
  3. You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.

Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.

mdma
Now that you're no longer a newbie, I'm sure others would appreciate if you went back and edited in the hyperlinks in this post. I'm going to do some research on what you describe about and I'll be back with feedback. Thanks for the help.
Oren
I've edited the links.
mdma
Turns out the application has a COM interface. I'm going to try and use Jacob. (Might need to ask a couple more questions about that, heh.) Thanks again.
Oren
You're welcome, and good luck with COM.
mdma