我有以下情况:我有一个特殊的 3D 程序,我需要它能够在不更改程序本身的情况下对多点触控事件做出反应。因此我需要一个映射器程序,它接收Windows 7的多点触控事件,将它们转换为相应的鼠标和键盘事件,并将这个模拟的事件发送给3D程序,以便它可以处理这些事件。
我已经阅读并尝试了很多,我目前的方法是在 3D 程序上设置一个几乎透明的覆盖窗口来捕获多点触控事件。但这也是问题所在,我无法以可用的方式将生成的鼠标事件转发到底层 3D 程序。现在我使用了诸如 mouse_event、SendMessage 等 pinvoke 函数,但它们都不适合我。因为我总是必须把 3D 程序放在前面,所以发送事件,然后我需要把我的映射程序再次放在前面。这很糟糕。
所以我的问题或多或少,有没有一种很好的工作方法来做我上面提到的事情?或者至少是一种将鼠标和键盘事件发送到后台进程的好方法?
希望任何人都可以给我一个提示或建议....
这是我现在模拟鼠标点击的方式:
private void OnMouseDown(object sender, MouseEventArgs e)
{
Point position = this.PointToScreen(new Point(e.Location.X, e.Location.Y));
//Simulate the mouse event on the given position
this.Visible = false;
Cursor.Position = position;
mouse_event(Convert.ToUInt16(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
}
private void OnMouseUp(object sender, MouseEventArgs e)
{
Point position = this.PointToScreen(new Point(e.Location.X, e.Location.Y));
//Simulate the mouse event on the given position
Cursor.Position = e.Location;
mouse_event(Convert.ToUInt16(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
this.Visible = true;
}
//Get a handle to the mouse event manager
[DllImport("user32.dll")]
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);