s.k.paul
s.k.paul

Reputation: 7291

Handle Ctrl+Shift+A in WinForm Application

I'm trying to capture Ctrl+Shift+A keydown event in an WinForm application. Here is what I've tried so far-

if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control && e.Modifiers == Keys.Shift) 
{
    this.Close();
}

But it's not working. I've set KeyPreview = true.

Any idea?

Upvotes: 2

Views: 155

Answers (3)

Code It
Code It

Reputation: 396

Try this:

if (e.KeyCode == Keys.A && e.Modifiers == (Keys.Control | Keys.Shift))
{
     this.Close();
}

Or this:

if (e.Control && e.Shift && e.KeyCode == Keys.A)
{
   this.Close();
}

Upvotes: 3

GMaiolo
GMaiolo

Reputation: 4628

Personally I think this is the simplest way.

if (e.Control && e.Shift && e.KeyCode == Keys.A)
{
   this.Close();
}

Upvotes: 2

ElektroStudios
ElektroStudios

Reputation: 20474

In your KeyDown event handler:

if (e.KeyCode == Keys.A && e.Control && e.Shift) {
    // ...
}

Upvotes: 2

Related Questions