Detect when user takes a screen shot in windows with print screen?

随声附和 提交于 2020-01-04 07:10:10

问题


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:


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 ) {}  
}  


来源:https://stackoverflow.com/questions/10793508/detect-when-user-takes-a-screen-shot-in-windows-with-print-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!