我知道如何处理关键事件,即
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 事件处理程序。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)