1

I'm using Keys type to detect pressed keys.

At some place I do comparison like this:

if (keyData == Keys.Control)
//do something

where keyData is the key pressed of type Keys

However keyData contains

ControlKey | Control

So of course comparison doesn't work because Keys.Control contains only Control.

So what is the correct way to compare them?

Cher
  • 2,789
  • 10
  • 37
  • 64

1 Answers1

1

This is how I do it:

private void mainImage_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.LeftCtrl) // System.Windows.Input.Key
        LeftCtrlButtonIsPressed = true; // raise a flag
}
Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104