PrajaktaB
PrajaktaB

Reputation:

Mouse Listener Question

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?

Upvotes: 1

Views: 399

Answers (4)

Shanmu
Shanmu

Reputation: 938

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)

Upvotes: 0

Real Red.
Real Red.

Reputation: 5039

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.

Upvotes: 1

OscarRyz
OscarRyz

Reputation: 199195

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?

Upvotes: 0

Paxic
Paxic

Reputation: 1760

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.

Upvotes: 1

Related Questions