Globally Catching KeyDown/KeyPress

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
I've written a Print Screen routine that captures *all* of the information displayed by my project (2 or 3 forms), saves it to a defined image type in a folder that the operator selects, then displays the image in an external viewer.

My operators, however, are still trying to use the "Print Screen" key and pasting their images on their own because they forget that my tool is there.

So, I want to capture the "Print Screen" key. I've written these two routines and wired them to the MDI Form, but they never fire:
Code:
void MdiForm_KeyDown(object sender, KeyEventArgs e) {
  if (e.KeyCode == Keys.PrintScreen) {
    ScreenCapture(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
    e.Handled = true;
  }
}

void MdiForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
  if (e.KeyCode == Keys.PrintScreen) {
    ScreenCapture(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
  }
}
I'm guessing the problem is that other forms (and their controls) have focus, so the events are being sent to there instead of to my routines.

How can I wire up my routine so that I can catch key presses *without* having to wire each and every control to these two events?
 
I just set the MDI form's KeyPreview property to true. The event handlers for KeyDown and KeyPress now catch *regular* keys, but I still can't catch that Print Screen button!
 
Back
Top