如何全局钩住触摸事件并知道触摸的X Y位置?

时间:2019-01-28 00:50:39

标签: c# wpf touch

需要在我的wpf应用程序外部的Windows 10上拾取触摸屏上的位置X Y。 我在一些帖子中读到可以使用RegisterPointerInputTarget

我尝试将所有触摸重定向到我的应用。 应该使用RegisterPointerInputTarget应该像我显示的代码一样容易,但是不知道我做错了什么。

我也找到了一些类似的工作代码; https://github.com/yingDev/WGestures/blob/master/WGestures.Core/Impl/Windows/TouchHook.cs

有什么方法可以进行全局挂钩触摸事件并在发生触摸时知道位置X Y?

我应该使用RegisterPointerInputTarget吗?

我感谢任何信息和/或代码示例。

using System;
using System.Windows;
using System.Runtime.InteropServices;




 namespace WpfApp17
 {

 public partial class MainWindow : Window
 {

    public enum PointerInputType
    {
        POINTER = 0x00000001,
        TOUCH = 0x00000002,
        PEN = 0x00000003,
        MOUSE = 0x00000004,
    }
    [DllImport("User32")]
    static extern bool RegisterPointerInputTarget(IntPtr hwnd, PointerInputType pointerType);


    public MainWindow()
    {
        InitializeComponent();
        IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle;
        var ok = RegisterPointerInputTarget(hWnd, PointerInputType.TOUCH);

    if (!ok)

       {
           MessageBox.Show("Error!" );
          return; 
      }
      else
      {
         MessageBox.Show("TouchHook Redirected.");
      }


  }


  }

}

0 个答案:

没有答案