Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the user pressing F10 in WPF

My WPF application has behaviour triggered by the functions keys (F1-F12).

My code is along these lines:

private void Window_KeyDown(object sender, KeyEventArgs e)
{
    switch (e.Key)
    {
        case Key.F1:
        ...
        case Key.F2:
        ...
    }
}

This works for all F-keys except F10. Debugging, I find that e.Key == Key.System when the user presses F10.

In the enum definition, F10 = 99 and System = 156, so I can rule out it being a duplicate enum value (like PageDown = Next = 20).

So, how do I tell when the user presses F10?

Is it safe to check for Key.System instead? This feels a little dirty - might it be possible that Key.System would ever result from some other key being pressed? Or is there some setting somewhere that will make F10 report as Key.F10?

like image 942
teedyay Avatar asked Jan 20 '10 17:01

teedyay


1 Answers

In addition to Yacoder's response, use the following to check for the F10 key:

case Key.System:
  if (e.SystemKey == Key.F10)
  {
    // logic...
  }

The SystemKey property will tell you which System key was pressed.

like image 104
Will Eddins Avatar answered Sep 26 '22 05:09

Will Eddins