需要在 Windows 10 上的屏幕上拾取触摸位置 XY(在我的 wpf 应用程序之外)。我在一些帖子中读到可以使用 RegisterPointerInputTarget
我尝试将所有触摸重定向到我的应用程序。应该使用 RegisterPointerInputTarget 应该像我展示的代码一样简单,但不知道我做错了什么。
我还发现了一些像这样的工作代码;https://github.com/yingDev/WGestures/blob/master/WGestures.Core/Impl/Windows/TouchHook.cs
有某种方法可以全局钩子触摸事件并知道触摸发生时的位置 XY 吗?
我应该使用 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.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
}