将信息添加到输入-UWP中TouchDevice的备选方案

本文关键字:TouchDevice 方案 -UWP 信息 添加 输入 | 更新日期: 2023-09-27 17:58:14

我想在我的UWP应用程序上为触摸/鼠标点击等添加更多信息。在WPF中,可以使用TouchDevice类,从中继承并扩展它:

public class MyTouchDevice : TouchDevice
{
    public override GetTouchPoint(IInputElement relativeTo)...
    }
    ...

将类添加到输入消息传递系统:

MyTouchDevice device = new MyTouchDevice(...);
device.Activate();

并使用它:

private void OnTouchDown(object sender, TouchEventArgs e)
{
    if (e.TouchDevice is MyTouchDevice)
    {
    ...

我如何在UWP应用程序中做到这一点?没有TouchDevicePointerDevice是完全不同的东西。除此之外,几乎每个类(PointerPointPointer等)都是密封的。

将信息添加到输入-UWP中TouchDevice的备选方案

恐怕UWP中没有这样的API,但您可以尝试使用UIViewSettings.GetForCurrentView|GetForCurrentView方法来检测当前的交互模式,然后也许可以完成您的工作:

switch (UIViewSettings.GetForCurrentView().UserInteractionMode)
{
    case UserInteractionMode.Mouse:
        //TODO:
        break;
    case UserInteractionMode.Touch:
    default:
        //TODO:
        break;
} 

如果这没有帮助,我的建议是,你可以提交一个请求,添加这些新功能,以便通过Windows反馈工具进行开发。