Reputation: 13
I try to get the non-ModifierKeys from the pressKey event. To get the ModifierKey i use:
if (Control.ModifierKeys == Keys.Control)
But how do i get the non-ModifierKeys? Not just a specific key. But all combination a-z 0-9.
I want to know if CTRL
+A or CTRL
+5 or CTRL
+B is pressed or any combinations.
Upvotes: 1
Views: 86
Reputation: 4505
If you are trying to identify whether a the keypress was a letter or a digit you could do something like
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetterOrDigit(e.KeyChar))
{
//do A
}
else
{
//do B
}
}
But if you want which key was pressed, you could handle the KeyDown event whose KeyEventArgs will have which key was pressed.
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
Keys keyPressed = e.KeyCode;
}
Upvotes: 0
Reputation: 127593
Control
does not provide a property that lists all the pressed keys. You need to pick it up in a event, like KeyPress
.
Upvotes: 1