访问通用Windows App(IoT)中的原始键盘输入 [英] Access raw keyboard input in Universal Windows App (IoT)
问题描述
我正在尝试构建一个应用程序,该应用程序将接受来自模拟键盘的遥控器的键盘输入.我需要从遥控器捕获所有键,包括提高/降低音量(它模拟多媒体键盘,fwiw).我不知道如何在UWA中做到这一点. 我已经尝试过Windows.UI.Input.KeyboardDeliveryInterceptor和Windows.UI.Core.CoreWindow.GetForCurrentThread().KeyDown,它们捕获一些输入,但不是所有键(它不捕获特殊键).
I'm trying to build an app that will accept keyboard input from a remote control that emulates a keyboard. I need to capture all keys from the remote, including volume up/down (it emulates a multimedia keyboard, fwiw). I can't figure out how to do that in a UWA. I've tried Windows.UI.Input.KeyboardDeliveryInterceptor and Windows.UI.Core.CoreWindow.GetForCurrentThread().KeyDown, which capture some input, but not all keys (it doesn't capture the special keys).
我不打算将此应用程序包含在App Store中,因此我可以分配所需的任何功能,包括受限功能.我试图直接访问HID设备,但事实证明键盘被阻止了().
I don't plan to include this app in the App Store so I can assign any capability that I need, including restricted. I tried to access the HID device directly, but it turns out keyboards are blocked ().
有什么想法吗?
推荐答案
简短答案
关键部分是在后面的代码中启用拦截器:
The key part is enabling the interceptor in the code behind:
deliveryInterceptor.IsInterceptionEnabledWhenInForeground = true;
,并在应用清单中声明"inputForegroundObservation"功能:
and declaring the "inputForegroundObservation" capability in the app manifest:
<rescap:Capability Name="inputForegroundObservation" />
好答案
将此添加到Package.appxmanifest:
Add this to Package.appxmanifest:
命名空间对受限功能的引用:
Namespace reference to restricted capabilities:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
添加为功能"标记的子代:
Add as child for Capabilities tag:
<rescap:Capability Name="inputForegroundObservation" />
然后将其添加到您的代码后面(例如MainPage.xaml.cs):
Then add this in your code behind (say MainPage.xaml.cs):
public MainPage()
{
this.InitializeComponent();
var _deliveryInterceptor = KeyboardDeliveryInterceptor.GetForCurrentView();
UpdateTextBox($"Hash interceptor: {_deliveryInterceptor.GetHashCode()} \n");
_deliveryInterceptor.IsInterceptionEnabledWhenInForeground = true;
_deliveryInterceptor.KeyUp += _deliveryInterceptor_KeyEventReceived;
_deliveryInterceptor.KeyDown += _deliveryInterceptor_KeyEventReceived;
}
private void _deliveryInterceptor_KeyEventReceived(KeyboardDeliveryInterceptor sender, Windows.UI.Core.KeyEventArgs
{
//Process KeyUp/KeyDown
}
这篇关于访问通用Windows App(IoT)中的原始键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!