禁用与 UWP 应用程序的键盘交互 [英] Disable keyboard interaction with UWP app

查看:31
本文介绍了禁用与 UWP 应用程序的键盘交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 UWP 应用程序,我希望禁用与我的应用程序的键盘交互.这意味着当按下键盘上的任何键时,我的应用程序不应以任何方式响应.

I am building a UWP application and I wish to disable the keyboard interaction with my application. This means my app should not in any way respond when any key on the keyboard is pressed.

这能实现吗?我可以有选择地禁用与某些键(如 Tab 键等)的交互吗?

Is this achievable? Can I selectively disable interaction with some keys like the Tab key etc.

推荐答案

是的,您可以使用 KeyboardDeliveryInterceptor 类.需要注意以下几点:

Yes, you can use the KeyboardDeliveryInterceptor class for this. Couple of things to note with this:

  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
    }
};

这篇关于禁用与 UWP 应用程序的键盘交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆