Ctrl key press condition in WPF MouseLeftButtonDown event-handler

Viewed 29358

How I can add an additional condition for a certain keyboard key, to a WPF MouseLeftButtonDown event-handler?

For example Ctrl + key

private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{         
    ...
}
4 Answers

As Grzegorz Godlewski said above, Keyboard.Modifiers.HasFlag(ModifierKey.Control) can be used.

Although @l33t points out it is not very performant, in the comment it appears there have been improvements in the performance of HasFlag in .NET 4.5/4.6. (see benchmarks results in What is it that makes Enum.HasFlag so slow? and the comments below, and also in this answer).

But still nothing as fast as doing a native check (i.e. flagsToCheck & flag != 0 ) judging by the conclusion here.

Related