我知道如何处理关键事件,即
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/