0

Hi,

I've created a small application that allows the user to capture the screenshot and save the image at a user defined location. It also allows the user to capture the screenshot of the active window as well.

The issue is with the active window. I have learnt that Java does not provide a method to get the screenshot of the active window. So, I googled and found that developers have been using the Alt+PrntScrn to get the screenshot and get the image from the clipboard.

The code for this is:

                  robot.keyPress(KeyEvent.VK_ALT);
                  robot.keyPress(KeyEvent.VK_PRINTSCREEN);
                  robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
                  robot.keyRelease(KeyEvent.VK_ALT);    
                  Thread.sleep(1500);
                  RenderedImage image = (RenderedImage)getClipboard();
                  saveToImage(image,targetLocation);

Now what happens is that when the Alt key is pressed by the robot class, the focus goes on the toolbar of the application of which the user wants to get the screenshot and the screenshot is taken of the toolbar and not that of the window that the user has focus on.

Please advise on how to solve this problem.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by anuj_sharma
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.