gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:14:31 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com