我正在尝试模拟鼠标左键单击和左键释放来进行自动拖放操作。
目前是在C# Winforms(是的,Winforms :|)中进行,并且有点棘手。
基本上,一旦发送了单击命令,我希望根据Kinect输入更新光标位置。Kinect方面的问题很好解决,但我不确定如何找到按钮是否仍然被按下。
这是我目前正在使用的代码+一些伪代码来更好地解释自己(使用do while)。
class MouseImpersonator
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const int leftDown = 0x02;
private const int leftUp = 0x04;
public static void Grab(int xPos, int yPos)
{
Cursor.Position = new Point(xPos + 25, yPos + 25);
mouse_event(leftDown, (uint) xPos, (uint) yPos, 0, 0);
//do
//{
//Cursor.Position = new Point(KinectSettings.movement.LeftHandX, KinectSettings.movement.LeftHandY);
//} while (the left mouse button is still clicked);
}
public static void Release(int xPos, int yPos)
{
Cursor.Position = new Point(xPos + 25, yPos + 25);
mouse_event(leftUp, (uint) xPos, (uint) yPos, 0, 0);
}
}
我在谷歌上搜索了一下,除了 WPF 的等价物之外找不到我需要的任何东西:http://msdn.microsoft.com/en-us/library/system.windows.input.mouse.aspx
我有点力不从心,但任何帮助都将不胜感激。
卢卡斯。
-
-