I'm working with WPF KeyDown event (KeyEventArgs from Windows.Input). I need to recognize when user pressed F1 alone and Ctrl+F1.
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key==Key.F1 && Keyboard.IsKeyDown(Key.LeftCtrl))
{
MessageBox.Show("ctrlF1");
}
if (e.Key == Key.F1 && !Keyboard.IsKeyDown(Key.LeftCtrl))
{
MessageBox.Show("F1");
}
}
My problem is that when I press Ctrl+F1 plain F1 messagebox would fire too. I tried to add e.Handled to Ctrl+F1 case, but it doesn't help.
Use:
In your case both options are fired, because you press the F1 key in both cases.