检测用户在WPF中按F10 [英] Detecting the user pressing F10 in WPF

查看:104
本文介绍了检测用户在WPF中按F10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WPF应用程序具有由功能键( F1 - F12 )触发的行为.

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:
        ...
    }
}

这适用于除 F10 之外的所有F键.调试时,当用户按下 F10 时,我发现e.Key == Key.System.

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

在枚举定义F10 = 99System = 156中,因此我可以排除它是重复的枚举值(如PageDown = Next = 20).

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

那么,我如何知道用户何时按下 F10 ?

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

检查Key.System是否安全?感觉有点脏-按下其他键是否可能会导致Key.System?还是在某处有某些设置会使 F10 报告为Key.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?

推荐答案

除了Yacoder的响应外,请使用以下命令检查 F10 键:

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

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

SystemKey 属性将告诉您按下了哪个系统键.

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

这篇关于检测用户在WPF中按F10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆