tags:

views:

84

answers:

1

How can I capture keys on a WinForms application when the application is in focus?

I have tried using the Form_KeyDown and Form_KeyUp events but they don't work the way I want them to.

+2  A: 

Set KeyPreview to true

Here's a sample OnKeyDown override for your form that eats the keystroke too:

protected override void OnKeyDown(KeyEventArgs e)
{
    e.SuppressKeyPress = true; // do this to 'eat' the keystroke
    base.OnKeyDown(e);
}
John JJ Curtis
Thanks man. .
Joan Venge
No problem, enjoy!
John JJ Curtis
By eating you mean, it doesn't get propagated to other events, right?
Joan Venge
Yes, it will not pass it along to any other events.
John JJ Curtis