Ehel
Ehel

Reputation: 13

Get the non-ModifierKey c#

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

Answers (2)

haku
haku

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

Scott Chamberlain
Scott Chamberlain

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

Related Questions