windows-8 - 使用 C# 在 Windows 8 Store 应用程序中处理 VirtualKey

标签 windows-8 windows-store-apps

我知道如何处理关键事件,即

private void Page_KeyUp(object sender, KeyRoutedEventArgs e)
{
  switch (e.Key)
  {
    case Windows.System.VirtualKey.Enter:
      // handler for enter key
      break;

    case Windows.System.VirtualKey.A:
      // handler for A key
      break;

    default:
      break;
  }
}

但是如果我需要区分小写的“a”和大写的“A”怎么办?另外,如果我想处理像百分号“%”这样的键怎么办?

最佳答案

在别处得到了答案。对于那些有兴趣...

public Foo()
{
    this.InitializeComponent();
    Window.Current.CoreWindow.CharacterReceived += KeyPress;
}

void KeyPress(CoreWindow sender, CharacterReceivedEventArgs args)
{
    args.Handled = true;
    Debug.WriteLine("KeyPress " + Convert.ToChar(args.KeyCode));
    return;
}

更好的是,移动 Window.Current.CoreWindow.CharacterReceived += KeyPress;到 GotFocus 事件处理程序中,并添加 Window.Current.CoreWindow.CharacterReceived -= KeyPress;进入 LostFocus 事件处理程序。

关于windows-8 - 使用 C# 在 Windows 8 Store 应用程序中处理 VirtualKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16783820/

相关文章:

c# - 使用 Metro 风格应用程序启动桌面应用程序

Windows RT .NET 兼容性

javascript - WinJS 缓存 facebook 个人资料图片

c# - Mvvmcross 中是否有任何错误记录框架?

c# - 在正确的时间恢复 GridView 上的滚动位置

file-io - headless (headless)运行 Metro 应用程序

c# - UWP Store App 中的隐私政策 ?提交应用商店认证失败

c# - Windows 8.1中的http客户端取消请求

css - 自定义复选框/ radio 设计怪异

c# - Windows(手机)8.1 相机使用