tags:

views:

132

answers:

4

I am developing a screen capturing utility in Java & I want to capture any background window, when I click on that particular window. But I am not getting how to add mouseClicked event to background window. Can somebody please help me?

+1  A: 

I may be way off base but if the other window is not a Java window then it should be outside the Java sandbox. To interact with it requires a native API which is anathema to Java.

Paxic
A: 

If that window is not part of your application you can't do much with it.

Otherwise you just have to add the mouse listener to that window too.

What's your situation?

OscarRyz
A: 

Quite obviously as it is you can't interact with other application windows. It can be any random window in your case I presume. Therefore, your mouselistener approach is not correct.

Rather, try to approach it like fetching pixel information displayed on the screen. There is an awt package java.awt.Robot or something that could be used for your purpose. If you want to implement capturing of active window then see if there are java APIs to interact with O.S. and get information of current active window and it's pixel co-ordinates. The co-ordinates could then be supplied to the rectangle attribute that is used with java.awt.Robot APIs to define screen capture area.

Chandan .
A: 

java.awt.Robot has a method createScreenCapture(Rectangle screenRect) to capture screenshots. http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html

however, to get the current active window you would have to use OS specific extensions (mostly via JNI)

Shanmu