GLControl定义了各种鼠标事件(例如MouseDown
,MouseMove
等)。即使使用触摸或手写笔进行交互,也会引发这些事件。
但是,我很想知道是否有办法区分这些事件。换句话说,我想以不同于鼠标事件的方式处理触摸事件。怎么办呢?
答案 0 :(得分:1)
从我所看到的情况来看,你必须自己决定这个事件。这question和this MSDN page帮助了我。
总结一下,为了确定触发事件的内容,您需要从GetMessageExtraInfo()
致电user32.dll
。 MSDN文章描述了如何根据调用结果上设置的位来区分三个输入。这是我为此目的掀起的代码:
/// <summary>
/// The sources of the input event that is raised and is generally
/// recognized as mouse events.
/// </summary>
public enum MouseEventSource
{
/// <summary>
/// Events raised by the mouse
/// </summary>
Mouse,
/// <summary>
/// Events raised by a stylus
/// </summary>
Pen,
/// <summary>
/// Events raised by touching the screen
/// </summary>
Touch
}
/// <summary>
/// Gets the extra information for the mouse event.
/// </summary>
/// <returns>The extra information provided by Windows API</returns>
[DllImport("user32.dll")]
private static extern uint GetMessageExtraInfo();
/// <summary>
/// Determines what input device triggered the mouse event.
/// </summary>
/// <returns>
/// A result indicating whether the last mouse event was triggered
/// by a touch, pen or the mouse.
/// </returns>
public static MouseEventSource GetMouseEventSource()
{
uint extra = GetMessageExtraInfo();
bool isTouchOrPen = ((extra & 0xFFFFFF00) == 0xFF515700);
if (!isTouchOrPen)
return MouseEventSource.Mouse;
bool isTouch = ((extra & 0x00000080) == 0x00000080);
return isTouch ? MouseEventSource.Touch : MouseEventSource.Pen;
}
出于我的目的,我在GLControl类中重写了OnMouse*
个事件并使用上面的函数执行检查并相应地调用我的自定义事件处理程序。