Detect when user takes a screen shot in windows wi

2019-07-11 02:26发布

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!

1条回答
仙女界的扛把子
2楼-- · 2019-07-11 03:05

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 ) {}  
}  
查看更多
登录 后发表回答