How I can add an additional condition for a certain keyboard key, to a WPF MouseLeftButtonDown
event-handler?
如何向WPF MouseLeftButtonDown事件处理程序添加某个键盘键的附加条件?
For example Ctrl + key
例如Ctrl + key
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
...
}
3 个解决方案
#1
60
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
if(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) {
MessageBox.Show("Control key is down");
} else {
MessageBox.Show("Control key is up");
}
}
#2
37
If you want to detect modifiers only, you can also use:
如果你只想检测修饰词,你也可以使用:
if (Keyboard.Modifiers == ModifierKeys.Control) {}
if (Keyboard.Modifiers == ModifierKeys.Shift) {}
etc. More here.
等这里。
#3
6
In .NET 4.0 you could use:
在。net 4.0中,你可以使用:
Keyboard.Modifiers.HasFlag(ModifierKeys.Control)
#1
60
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
if(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) {
MessageBox.Show("Control key is down");
} else {
MessageBox.Show("Control key is up");
}
}
#2
37
If you want to detect modifiers only, you can also use:
如果你只想检测修饰词,你也可以使用:
if (Keyboard.Modifiers == ModifierKeys.Control) {}
if (Keyboard.Modifiers == ModifierKeys.Shift) {}
etc. More here.
等这里。
#3
6
In .NET 4.0 you could use:
在。net 4.0中,你可以使用:
Keyboard.Modifiers.HasFlag(ModifierKeys.Control)