如何全局检测点击(触摸输入)而不是鼠标点击? [英] How to detect tapping (touch input) globally instead of mouse clicking?

查看:17
本文介绍了如何全局检测点击(触摸输入)而不是鼠标点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个在用户触摸屏幕时显示自己的应用.它不应该适用于点击.我在 Windows 7/8 中查找了触摸处理程序.但是我看到每个触摸窗口都必须用RegisterTouchWindow注册

I want to make an app that shows itself when the user touches his screen. It shouldn't work for click. I looked up for the touch hanlders in Windows 7/8. But I saw that every touch window must be registered with RegisterTouchWindow

TL;DR

有没有办法让我的窗口外的触摸点位置(全局)?

Is there a way to get the touch points position outside my window (globally)?

推荐答案

Win 8 应用不再需要RegisterTouchWindow.

RegisterTouchWindow is not necessary for Win 8 apps any more.

据我所知,有几种方法可以实现您的目的,但有一些限制.

As far as I known, there are several ways to achieve your purpose with some limitations.

  1. 这篇文章在这里有效在 Win 7 和8. 但是需要提供触摸屏的vendor ID和product ID.您的应用程序可能无法在某些触摸设备上正常工作.

  1. This article here works on both Win 7 & 8. But the vendor ID and the product ID of the touchscreen is required. There is a possibility that your application won't work properly with some touch device.

在 Win 8 上使用 RegisterPointerInputTarget.从我的调试来看,windows 8的触控机制有其独特的特点.在touch down和touch up之间,所有的touch事件都会被发送到第一个touch事件的window,无论是window被最小化还是被另一个window覆盖,或者在其后期设置WS_EX_TRANSPARENT属性.如果第一个被销毁,则只能将按下和释放之间的触摸事件共享到另一个窗口.使用此 API,所有的触摸事件都将发送到注册的窗口.在 UnregisterPointerInputTarget 被注册的窗口调用,或者使用 InjectTouchInput.注册的输入目标注入的输入不会被拦截."请注意,使用此 API 需要 UI 访问权限.可在此处找到示例.

Use RegisterPointerInputTarget on Win 8. From my debugging, the windows 8 touch mechanism has its unique characteristics. Between a touch down and a touch up, all the touch events will be sent to the window which receives the first touch event, no matter the window is minimized or covered by another window or set WS_EX_TRANSPARENT attribute in its later period. The touch events between one pressing and releasing can only be shared to another window if the first one is destroyed. Using this API, all the touch events will be sent to the registered window. Other windows cannot receive touch events any more until UnregisterPointerInputTarget is called by the registered window, or the touch input is injected back into the system by using InjectTouchInput. "Input injected by the registered input target will not be intercepted." Please notice that UI Access privilege is required for using this API. A sample can be found in here.

Windows 挂钩.对于 Win 7/8 上的桌面应用程序,可以使用 SetWindowsHookEx 轻松挂钩触摸事件 与 WH_CALLWNDPROC 或 WH_GETMESSAGE.对于 Win 8 上的 Metro 应用程序,在窗口的消息循环中只能检测到第一个指针事件.尽管可以通过单击或轻击来发生指针事件,但 GetPointerType 可以告诉您它是触摸指针还是鼠标指针.可以在此处找到使用挂钩的示例.

Windows hook. For desktop app on Win 7/8, touch events can be easily hooked by using SetWindowsHookEx with WH_CALLWNDPROC or WH_GETMESSAGE. For metro app on Win 8, only the first pointer event can be detected in the message loop of the window. Although a pointer event can be occurred by either a click or a tap, GetPointerType can tell you if its a touch pointer or a mouse pointer. Samples for using hooks can be found at here.

处理指针事件的代码片段:

A code snippet for handling pointer events:

switch(Msg)  
{  
...  
case WM_POINTERENTER:  
case WM_NCPOINTERDOWN:  
case WM_NCPOINTERUP:  
case WM_NCPOINTERUPDATE:  
case WM_POINTERACTIVATE:  
case WM_POINTERCAPTURECHANGED:  
case WM_POINTERDOWN:  
case WM_POINTERLEAVE:  
case WM_POINTERUP:  
case WM_POINTERUPDATE:  
    {  
        UINT32 pointerId = GET_POINTERID_WPARAM(wParam);  
        POINTER_INPUT_TYPE pointerType;  

        if (GetPointerType(pointerId, &pointerType))  
        {
            if (pointerType == PT_TOUCH)   
            {  
                ...  
            }  
        }  
    }  
    break;  
...

这篇关于如何全局检测点击(触摸输入)而不是鼠标点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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