Reputation: 21
How to detect ctrl + e + h combination in c# winform please help...
if (e.Control && (e.KeyCode == Keys.E && e.KeyCode == Keys.H))
{
this.buttonExpenseHeads.PerformClick();
}
Upvotes: 1
Views: 272
Reputation: 301
Below sample code will help you to achieve your requirement.
Define global variable as below. It will track last key pressed. I.e. E.
Keys lstKeyPressed;
Use below code in KeyDown event.
if (Control.ModifierKeys == Keys.Control && e.KeyCode == Keys.H && lstKeyPressed == Keys.E)
{
this.buttonExpenseHeads.PerformClick(); //Raise button click as you mentioned.
}
lstKeyPressed = e.KeyCode;
Please note that above sample code will work only for key combination Ctrl + E + H, not for Ctrl + H + E.
Upvotes: 1