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

后端 未结 2 1041
一个人的身影
一个人的身影 2021-01-11 09:11

In my WPF App, how do I get the state of the shift, ctrl and alt keys in my mouse event handler? I seem to remember in MF

2条回答
  •  广开言路
    2021-01-11 10:05

    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

提交回复
热议问题