检测是否WM_MOUSEMOVE是通过触摸/笔引起的 [英] Detect if WM_MOUSEMOVE is caused by touch/pen

查看:221
本文介绍了检测是否WM_MOUSEMOVE是通过触摸/笔引起的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与WM_TOUCH实验和要检测,如果鼠标事件是由触摸/笔事件或由于合成的的实际的鼠标事件。

I am experimenting with WM_TOUCH and want to detect if mouse events are synthesized from touch/pen events or due to an actual mouse event.

官方的解决办法根据的 MSDN 是检查 GetMessageExtraInfo的结果()已设置为 0xFF515700

The official solution according to MSDN is to check if the result of GetMessageExtraInfo() has the upper 24 bits set to 0xFF515700.

这工作。 的时间大多数的。如果我用一个手指,一切都很好,但如果我使用一个以上的,释放最后一个导致与鼠标移动GetMessageExtraInfo()== 0 。此外,当窗口失去通过触摸对焦,多达3个鼠标移动的消息与 GetMessageExtraInfo()== 0 生成的。

This works. Most of the time. If I use one finger, all is well and good, but if I use more than one, releasing the last one causes a mouse move with GetMessageExtraInfo() == 0. Also, when the window loses focus via touch, up to 3 mouse move messages with GetMessageExtraInfo() == 0 are generated.

有没有的小鼠之间的歧义可靠的方式,触摸和笔输入?

Is there a reliable way of disambiguating between mouse, touch and pen inputs?

推荐答案

在公布确实显示的唯一可靠的方法通过物理鼠标生成鼠标消息之间辨别的链接,而那些响应合成触摸和笔输入。

The link you posted does show the only reliable way to discern between mouse messages generated by a physical mouse, and those synthesized in response to touch and pen input.

为了完整起见,这里是完全工作code。在code依赖于仅对在处理鼠标消息状态。在其他任何时间调用它具有未定义行为:

For completeness, here is the fully working code. The code relies on state that is valid only while handling a mouse message. Calling it at any other time has undefined behavior:

bool IsTouchEvent() {
    const LONG_PTR c_SIGNATURE_MASK = 0xFFFFFF00;
    const LONG_PTR c_MOUSEEVENTF_FROMTOUCH = 0xFF515700;

    LONG_PTR extraInfo = GetMessageExtraInfo();
    return ( ( extraInfo & c_SIGNATURE_MASK ) == c_MOUSEEVENTF_FROMTOUCH );
}

您所观察的其他 WM_MOUSEMOVE 的消息,是系统如何实现其内部簿记神器。例如,如果被显示或隐藏的窗口,鼠标光标可以是通过不同的窗口,现在,需要重新计算。要做到这一点,系统合成的人工 WM_MOUSEMOVE 消息。

The additional WM_MOUSEMOVE messages you are observing, are an artifact of how the system implements its internal bookkeeping. For example, if a window is shown or hidden, the mouse cursor may be over a different window now, and needs to be recalculated. To do this, the system synthesizes an artificial WM_MOUSEMOVE message.

这效果在Raymond Chen的博客中解释我是否能够得到伪WM_MOUSEMOVE消息?。

This effect is explained in Raymond Chen's blog: Why do I get spurious WM_MOUSEMOVE messages?.

这篇关于检测是否WM_MOUSEMOVE是通过触摸/笔引起的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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