Reputation: 59
I have looked on Stack Overflow and Google but I have yet to find an answer to my question. I want to detect when a key is pressed without the need of a text box.
Upvotes: 0
Views: 148
Reputation: 50276
All controls (including forms) have the KeyPress
, KeyDown
and KeyUp
events that you may use.
And there are corresponding OnKeyPress
, OnKeyDown
and OnKeyUp
methods that you can override in your own controls.
Upvotes: 0
Reputation: 43596
Override OnKeyPress
main Form
, this will catch the key presses
Winforms:
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
}
WPF: (will have to use OnKeyDown
or OnKeyUp
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
}
Upvotes: 1