RegisterPointerInputTarget不消耗所有输入 [英] RegisterPointerInputTarget not consuming all input

查看:59
本文介绍了RegisterPointerInputTarget不消耗所有输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 10中工作,我试图编写一个C ++程序来拦截所有触摸屏输入,但是某些输入仍在通过.

I'm working in Windows 10 and I am trying to write a C++ program that intercepts all touch screen input, however some input is still getting through.

我的代码使用PT_TOUCH调用RegisterPointerInputTarget来拦截触摸输入.这似乎大部分都是可行的,但是结果却不一致.作为测试,我添加了使用SendInput在检测到触摸输入时将鼠标缓慢向右移动的代码.例如,通过运行程序,我可以打开MS Paint并触摸屏幕.只要我保持手指不动,光标就会按预期缓慢地向右移动.但是,当我移动手指的那一刻,光标会捕捉到手指下的位置,就像程序完全没有运行一样.

My code calls RegisterPointerInputTarget with PT_TOUCH to intercept touch input. This mostly seems to work, however the results are inconsistent. As a test I have added code that uses SendInput to move the mouse slowly to the right whenever touch input is detected. With my program running I can, for example, open up MS Paint and touch the screen. So long as I hold my finger still on the cursor moves slowly to the right as expected. The moment I move my finger however, the cursor snaps to the position under my finger, just as it would if my program were not running at all.

再举一个例子,如果我在Visual Studio中尝试相同的操作,则光标再次向右缓慢移动,直到我移动手指,在该点上,光标跟随手指的移动,但缓慢地,滞后于其后面明显的延迟.

To give another example, if I try the same thing in visual studio, again the cursor moves slowly to the right until I move my finger at which point the cursor follows my fingers' movement but slowly, lagging be behind it with a significant delay.

设置我的窗口的代码如下:

The code to set up my window looks like this;

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable
   static const char* class_name = "DUMMY_CLASS";
   WNDCLASSEX wx = {};
   wx.cbSize = sizeof(WNDCLASSEX);
   wx.lpfnWndProc = WndProc;        // function which will handle messages
   wx.hInstance = hInst;
   wx.lpszClassName = class_name;
   HWND hWnd = 0;
   if (RegisterClassEx(&wx)) {
       hWnd = CreateWindowEx(0, class_name, "dummy_name", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
   }

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   if (RegisterTouchWindow(hWnd, 0) &&
       RegisterPointerInputTarget(hWnd, PT_TOUCH))
   {
     ...

我的消息处理代码如下:

and my message handling code looks like this;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_TOUCH:
    {
        INPUT Inputs[1] = { 0 };

        Inputs[0].type = INPUT_MOUSE;
        Inputs[0].mi.dx = 1;
        Inputs[0].mi.dy = 0;
        Inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE;

        SendInput(1, Inputs, sizeof(INPUT));

理想情况下,此测试代码将简单地为任何触摸输入移动光标.在修复或仅了解此方面的任何帮助将不胜感激!

Ideally this test code would simply move the cursor for any touch input. Any help in fixing or just understanding this would be greatly appreciated!

推荐答案

我在此方面取得了一些进展,但遇到了其他相关问题,我将在另一个问题中提出.该问题直播时,我将在此处添加评论.但是,解决此初始问题的关键是确保我返回0,而不从所有WM_POINTERENTER,WM_POINTERLEAVE,WM_POINTERUP,WM_POINTERDOWN,WM_POINTERUPDATE和WM_TOUCH消息调用DefWindowProc,并将我的SendInput调用放入处理WM_UPDATE消息的代码中.

I have made some progress with this but have hit other, related, problems I will ask about in a separate question. I will add a comment here when that question is live. The key to sorting out this initial issue however was to make sure I am returning 0, without calling DefWindowProc from all WM_POINTERENTER, WM_POINTERLEAVE, WM_POINTERUP, WM_POINTERDOWN, WM_POINTERUPDATE and WM_TOUCH messages, and to put my SendInput call into the code processing the WM_UPDATE message.

这篇关于RegisterPointerInputTarget不消耗所有输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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