所以我试图模拟鼠标左键单击和左键鼠标释放来进行一些自动拖放操作.
它目前处于C#Winforms(是的,winforms:|)并且有点像鹅.
基本上,一旦发送了Click,我希望它根据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
我有点超出我的深度,但任何帮助都非常感谢.
卢卡斯.
–
最佳答案 最简单的答案实际上是使用bool并只是检查一下发生了什么.
我在一个新线程上启动它,所以它没有打破其他一切.
希望你能整理一下这个.
public static void Grab(int xPos, int yPos)
{
_dragging = true;
Cursor.Position = new Point(xPos, yPos + offSet);
mouse_event(leftDown, (uint) xPos, (uint) yPos, 0, 0);
var t = new Thread(CheckMouseStatus);
t.Start();
}
public static void Release(int xPos, int yPos)
{
_dragging = false;
Cursor.Position = new Point(xPos, yPos + offSet);
mouse_event(leftUp, (uint) xPos, (uint) yPos, 0, 0);
}
private static void CheckMouseStatus()
{
do
{
Cursor.Position = new Point(KinectSettings.movement.HandX, KinectSettings.movement.HandY + offSet);
}
while (_dragging);
}