You have to combine the keys:
if (e.KeyCode == Keys.S && (Control.ModifierKeys == Keys.Control | Keys.Alt))
Keys
are flags - a single value is made up of all the individual enum values (any you want). So when you press both Control
and Alt
at the same time, that corresponds to a value of Keys.Control | Keys.Alt
. Of course, this means that neither Control.ModifierKeys == Keys.Control
nor Control.ModifierKeys == Keys.Alt
return true
- even though ModifierKeys
contains both of those, it's not equal to either of those.
As an extension, if you want to match Keys.Control
regardless of the status of the remaining modifier keys, you can do this:
(Control.ModifierKeys & Keys.Control) == Keys.Control
or
Control.ModifierKeys.HasFlag(Keys.Control)