试图模拟鼠标单击/拖动 [英] Attempting to Simulate Mouse Click / Drag

查看:316
本文介绍了试图模拟鼠标单击/拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想以模拟鼠标左键点击鼠标左键释放做一些自动化的拖放操作。

So I'm trying to simulate the left mouse click and the left mouse release to do some automated dragging and dropping.

这是目前在C#的WinForms(是的,的WinForms:|),并是一个有点鹅

It's currently in a C# Winforms (Yes, winforms :|) and is being a bit of a goose.

基本上,一旦点击发送,我希望它更新基于Kinect的输入光标位置。事物的Kinect的一面是好的,但我不知道如何找到,如果按钮仍然按下。

Basically, once a Click is sent, I want it to update the cursor position based upon the Kinect input. The Kinect side of things is fine but i'm not sure how to find if the button is still pressed or not.

下面是我目前使用的代码+一些伪码,以帮助更好地解释自己(的做时间)。

here's the code i'm currently using + some psuedocode to help better explain myself (the 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

我有点。我的深度,但任何帮助是极大的赞赏。

I'm a bit out of my depth, but any help is greatly appreciated.

卢卡斯


    -
    -

推荐答案

最简单的答案是逸岸使用布尔,只是检查,看看发生了什么事情。

The Easiest answer was infact to use a bool and just check to see what's going on.

我一开始就在一个新的线程,这样它就没有打破一切。

I started it on a new thread so it didn't break everything else.

Idealy你整理这一个点点。

Idealy you'd tidy this up a little bit.

    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);
    }

这篇关于试图模拟鼠标单击/拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆