Getting shift/ctrl/alt states from a mouse event? Getting shift/ctrl/alt states from a mouse event? wpf wpf

Getting shift/ctrl/alt states from a mouse event?


Assuming that you're still in the mouse event handler, you can check the value of Keyboard.Modifiers. I don't think that there is anyway to get modifier information from the event itself, so you have to interrogate the keyboard directly.


As per Andy's answer, you use Keyboard.Modifiers. I figured I would post a little example

Something like this in your event handler should work:

private void MyExampleButton_Click(object sender, RoutedEventArgs e){    if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {        System.Diagnostics.Debug.WriteLine("Control is pressed");    } else {        System.Diagnostics.Debug.WriteLine("Control is NOT pressed");    }}

Regards,Mike