禁用与UWP应用键盘交互

问题描述 投票:1回答:1

我建立一个应用程序UWP,我希望用我的应用程序禁用键盘交互。这意味着我的应用程序不应该以任何方式响应时,键盘上的任意键被按下。

这是可以实现的?我可以有选择地禁止与像Tab键等一些关键的相互作用

c# uwp windows-10 win-universal-app windows-10-universal
1个回答
2
投票

是的,你可以使用KeyboardDeliveryInterceptor类此。事情与此需要注意的几个:

  1. 你需要在你的appxmanifest文件中声明受限能力“inputForegroundObservation”:
<Capabilities>
  <Capability Name="internetClient" />
  <rescap:Capability xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" Name="inputForegroundObservation"/>
</Capabilities>
  1. 你不能拦截键选择,但是你可以在你的代码,特别是拦截响应按键和(按下tab键时,例如移动焦点)与所需的行动作出回应:
KeyboardDeliveryInterceptor interceptor = KeyboardDeliveryInterceptor.GetForCurrentView();
interceptor.IsInterceptionEnabledWhenInForeground = true;
interceptor.KeyUp += delegate(KeyboardDeliveryInterceptor sender, KeyEventArgs args)
{
    if (args.VirtualKey == Windows.System.VirtualKey.Tab)
    {
        // perform desired tab key action
    }
};
© www.soinside.com 2019 - 2024. All rights reserved.