views:

252

answers:

2

I want to have my app which is minimized to capture data selected in another app's window when the hot key is pressed. My app definitely doesn't have the focus. Additionally when the hot key is pressed I want to present a fading popup (Outlook style) so my app never gets focus.

At a minimum I want to capture the Window name, Process ID and the selected data. The app which has focus is not my application?

I know one option is to sniff the Clipboard, but are there any other solutions.

This is to audit the rate of data-entry in to another system of which I have no control. It is a mainframe emulation client program(attachmate aka java-hosted telnet with 3250 support).

The plan is

  1. complete data entry in Application X.
  2. Select a certain section of the screen in App X which is proof of data entry (transaction ID).
  3. Press the Magic Hotkey, which then 'sends' the selection to my App.
  4. From System.environment or system.Threading I can find the Windows logon.
  5. Similiarly I can also capture the time.
  6. All the data will be logged to SQL.
  7. Once Complete show Outlook style pop up saying the data entry has been logged.

Any thoughts.

A: 

It sounds like you need to set up a global keyboard hook to capture the hot key this code project article shows how to do that (in C# but it's not much different): http://www.codeproject.com/KB/cs/globalhook.aspx

And then you could use the FindWindow API to find the other apps window, then find the control that contains the "transaction ID" and use the WM_GETTEXT message to copy the text from it.

ho1
The app I am trying to suck data off is a Java applet. Since there is control per se, any thoughts. There seems to a single top-level window/handle of type SunAwtCanvas. In notepad or any regular windows app i see an actual handle for each control, but not in the applet's case.
ggonsalv
+1  A: 

Hooking the keyboard/mouse & screen scraping is pretty much the limit of what you can do with an applet. Remember Java is compiled to bytecode and run in the JVM. Because of the nature of the JVM, portability, and security concerns, you don't really have access to anything inside of the applet. All you will probably see from .Net is a "SunAwtFrame" classed window with no children.

The focus thing is doable, just use SendMessage (& other) API's to do what you need in the background and as long as you don't change the focus it will remain as is (ie. running code does not require focus)

As far as the data extraction goes, its going to come down to whether or not you can pull that info from the screen using some (potentially hardcore) image processing. Applets are a sort of no-mans land (from within .Net atleast), there is no JavaWindow.Textbox.GetAStringForMePlease().

For the record, there is an exception, if you physically control the applet. In that case you can make a sort of applet shell to hook the guts of the applet.

Stoney