gpt4 book ai didi

c# - 尝试模拟鼠标点击/拖动

转载 作者:太空狗 更新时间:2023-10-29 23:41:05 30 4
gpt4 key购买 nike

所以我试图模拟鼠标左键单击和鼠标左键释放来执行一些自动拖放操作。

它目前在 C# Winforms(是的,winforms :|)中并且有点笨拙。

基本上,一旦发送了点击,我希望它根据 Kinect 输入更新光标位置。 Kinect 方面的东西很好,但我不确定如何确定按钮是否仍被按下。

这是我目前正在使用的代码 + 一些伪代码来帮助更好地解释我自己(做的时候)。

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

关于c# - 尝试模拟鼠标点击/拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8561755/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com