Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试模拟鼠标单击/拖动_C#_Winforms_Mouseevent_Kinect - Fatal编程技术网

C# 尝试模拟鼠标单击/拖动

C# 尝试模拟鼠标单击/拖动,c#,winforms,mouseevent,kinect,C#,Winforms,Mouseevent,Kinect,因此,我尝试模拟鼠标左键单击和鼠标左键释放来进行自动拖放 它目前处于C#Winforms中(是的,Winforms:|),有点像鹅 基本上,发送单击后,我希望它根据Kinect输入更新光标位置。Kinect方面还可以,但我不确定如何确定按钮是否仍然按下 以下是我目前正在使用的代码+一些伪代码,以帮助更好地解释我自己(DoWhile) 我搜索过谷歌,除了WPF,找不到任何我需要的东西: 我有点力不从心,但非常感谢您的帮助 卢卡斯 - 如果鼠标左键按下,则以下代码应返回true;如果鼠标左键打开

因此,我尝试模拟鼠标左键单击和鼠标左键释放来进行自动拖放

它目前处于C#Winforms中(是的,Winforms:|),有点像鹅

基本上,发送单击后,我希望它根据Kinect输入更新光标位置。Kinect方面还可以,但我不确定如何确定按钮是否仍然按下

以下是我目前正在使用的代码+一些伪代码,以帮助更好地解释我自己(DoWhile)

我搜索过谷歌,除了WPF,找不到任何我需要的东西:

我有点力不从心,但非常感谢您的帮助

卢卡斯

    -
如果鼠标左键按下,则以下代码应返回true;如果鼠标左键打开,则返回false,控件为System.Windows.Forms.Control:

    Control.MouseButtons.HasFlag(MouseButtons.Left)

p、 最简单的答案是使用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);
    }

关于您的信息,名称空间是WPF的一部分。您是否尝试过在输入Grab时将布尔变量设置为true,在输入Release时将布尔变量设置为False?感谢Mark,狡猾的WPF已经调整了这个问题。我考虑过bool方法,但认为可能会有更优雅的方法。如果我/任何人想不出另一种方法,它就会起作用,只是尽量避免总是采取简单的方法:)声明是错误的,最后一个参数是IntPtr。通过IntPtr.Zero。我打赌这是用于csgo中的自动喷洒控制,这正是我所需要的
    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);
    }
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    private static extern void mouse_event(uint dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);

    [DllImport("user32.dll")]
    static extern bool SetCursorPos(int X, int Y);

    const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
    const uint MOUSEEVENTF_LEFTUP = 0x0004;
    const uint MOUSEEVENTF_MOVE = 0x0001;

    static void Drag(int startX,int startY,int endX,int endY)
    {
        endX = endX - startX;
        endY = endY - startY;
        SetCursorPos(startX, startY);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
        mouse_event(MOUSEEVENTF_MOVE, endX, endY, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    }