Keystroke combinations in c# winforms app
-
20-09-2019 - |
Question
does anyone know how i can setup an event handler so that if the keystrokes Alt + Shift + Ctrl + a letter will do something?
Solution
override void OnKeyDown( object sender, KeyEventArgs e )
{
bool myKeysPressed = (e.KeyCode == Keys.A) &&
((e.Modifiers & Keys.Alt) == Keys.Alt) &&
((e.Modifiers & Keys.Shift) == Keys.Shift) &&
((e.Modifiers & Keys.Control) == Keys.Control);
}
OTHER TIPS
Sames as Ed's, but shorter and more readable ;)
override void OnKeyDown( object sender, KeyEventArgs e )
{
bool myKeysPressed = (e.KeyCode == Keys.A) &&
e.Alt &&
e.Shift &&
e.Control;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow