I'm working on WPF application, and I'm showing modal/form when Key Combination is pressed, so in my case it is CTRL + F9
,
so here is my code:
//Listening on Window_PreviewKeyDown any key pressing
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
LockAllInputs();
}
if (e.Key == Key.Tab)
{
e.Handled = true;
}
if (e.Key == Key.F11)
{
this.Close();
}
// Opening modal when Key combination of CTRL AND F9 is pressed
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.F9)
{
MyModal modal = new MyModal();
// Do something
}
//Hitting a method when only F9 is pressed
if (e.Key == Key.F9)
{
//This is invoked everytime after CTRL+F9
CallAnotherMethod();
}
}
But the issue in my code is that, when I hit CTRL+F9
it works fine, but after that method that is invoked when F9
is pressed is being invoked also..
and that is something I want to avoid, CTRL+F9
is doing one thing, F9 is doing some another thing, so I dont want F9
to be invoked when CTRL+F9
is pressed...
Thanks guys