We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,599 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Capture screenshot of Active Window

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
2 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
anuj_sharma
Posting Whiz in Training
208 posts since Jul 2008
Reputation Points: 8
Solved Threads: 13
Skill Endorsements: 0

Can u send me the entire code format so that i can learn this.is it execute in command prompt

avinashbasetty
Newbie Poster
1 post since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

The application runs from the System Tray.

What else code do you need
??

anuj_sharma
Posting Whiz in Training
208 posts since Jul 2008
Reputation Points: 8
Solved Threads: 13
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0572 seconds using 2.64MB