加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:22:36 所属栏目:百科 来源:网络整理
导读:所以我试图模拟鼠标左键单击和左键鼠标释放来进行一些自动拖放操作. 它目前处于C#Winforms(是的,winforms:|)并且有点像鹅. 基本上,一旦发送了Click,我希望它根据Kinect输入更新光标位置. Kinect方面的情况很好,但我不知道如何找到按钮是否仍然按下. 这里的
所以我试图模拟鼠标左键单击和左键鼠标释放来进行一些自动拖放操作.

它目前处于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);

        //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,yPos + 25);
        mouse_event(leftUp,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,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,0);
    }

    private static void CheckMouseStatus()
    {
        do
        {
            Cursor.Position = new Point(KinectSettings.movement.HandX,KinectSettings.movement.HandY + offSet);
        } 
        while (_dragging);
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读