Yes, there is a simple solution to prevent grabbing information on your C# application screen with the keyboard's printscreen key without using keyboard hooks or calling COM interops. The solution makes use of Windows Forms Message Filter to trap keyboard events on your application window.
To trap keyboard events with Windows Message Filter, you need to implement the IMessageFilter interface and override the member PreFilterMessage(ref Message WM) method. This is the method called whenever a Form receives a keyboard or mouse event. You may want to read more about IMessageFilter.
The problem is that even though you have trapped the PrintScreen keypress event, the captured image will still persist to the clipboard. Therefore the simplest solution is to clear up the clipboard right after the PrintScreen is pressed on the keyboard.
This is how the overridden method will look like this:
public bool PreFilterMessage(ref Message WM)
{
Keys kCode = (Keys)(int)WM.WParam & Keys.KeyCode;
//block printscreen on KeyPress
if (kCode == Keys.Snapshot)
{
//remove the captured image from clipboard
Clipboard.Clear();
MessageBox.Show("Printscreen not allowed.");
return true;
}
return false;
}
Another thing is that, if this method returns true, the Windows GDI Message will not be received by the Form.
Note: The PrintScreen event can only be captured if the Application window is active.
Enjoy!