3

So, I need to, in my application, detect when the user takes a screenshot in Windows by using the print screen keyboard button. I noticed that Picasa does this and notifies the user, this would be very useful in my chat software. It needs to be able to detect it even when the window doesnt have focus. Anyone know how I would do this?

Thanks in advance!

Brandon
  • 4,486
  • 8
  • 33
  • 39
  • Related: [Java library for capturing active window screenshot](http://stackoverflow.com/questions/2475303/java-library-for-capturing-active-window-screenshot) – Paul Bellora May 29 '12 at 05:45
  • you cannot make it happen when the window doesn't have focus.. what you can do is do something when the window loses focus like minimizing the window. – mickeymoon Jul 15 '14 at 09:18

1 Answers1

2

The KeyEvent class has a key code called VK_PRINTSCREEN that represents the PrintScreen key...

To listen for it being pressed you would write a keylistener something like this...

public class PrintScrnListener implements KeyListener {  
    public void keyPressed( KeyEvent e ) {  
        if (e.getKeyCode() == KeyEvent.VK_PRINTSCREEN ) {  
            // Do whatever...  
        }  
    }  
    public void keyReleased( KeyEvent e ) {}  
    public void keyTyped( KeyEvent e ) {}  
}  
Pramod Kumar
  • 7,914
  • 5
  • 28
  • 37
  • Yeah but this event is only captured if the window has focus. I want to be able to capture this without having to have the window focused. I assume I will have to listen not for the key press but some sort of event triggered in Windows or something through a windows service. – Brandon May 29 '12 at 05:46