1

My objective is to allow users of my app to bringup what I'm calling my debug console by pressing CTRL + F11 on their keyboard.

Simply put, I need to call a ToggleDebug(); method, which will enable my debug tracing code and display the window. I'd like for my application to do this at any point when CTRL + F11 is pressed, regardless of where the user currently has focus the cursor as long as my application is the currently focused window.

My app is deployed through Click Once -- so its a partial trust type environment.

In an old VB6 app, I had been using a wend loop with call to DoEvents() and a windows API call... needless to say, I'm hoping there is a better way now.

Nate
  • 30,286
  • 23
  • 113
  • 184

1 Answers1

3

You can handle the PreviewKeyDown event of your window.

public MainWindow()
{
    InitializeComponent();
    this.PreviewKeyDown += new KeyEventHandler(MainWindow_PreviewKeyDown);
}

void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if ((e.Key == Key.F11) && (Keyboard.Modifiers == ModifierKeys.Control))
    { 

    }
}
ASanch
  • 10,233
  • 46
  • 32
  • Why are you recomending PreviewKeyDown vs KeyDown? – Nate Sep 29 '10 at 22:13
  • 2
    PreviewKeyDown on the window will surely get hit every time. KeyDown does not. For instance, if a control in your window internally handles KeyDown events and sets its e.Handled to True, that event will not get raised on the Window. – ASanch Sep 29 '10 at 22:23