Reputation: 7291
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
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
Reputation: 4628
Personally I think this is the simplest way.
if (e.Control && e.Shift && e.KeyCode == Keys.A)
{
this.Close();
}
Upvotes: 2
Reputation: 20474
In your KeyDown
event handler:
if (e.KeyCode == Keys.A && e.Control && e.Shift) {
// ...
}
Upvotes: 2