gpt4 book ai didi

c# - 如何以编程方式在 C# 中触发鼠标左键单击?

转载 作者:太空狗 更新时间:2023-10-29 20:53:38 25 4
gpt4 key购买 nike

如何以编程方式触发鼠标左键单击事件?

谢谢。

编辑:事件不是直接在按钮上触发的。我的目标是 Windows 平台。

最佳答案

执行鼠标点击:

 [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;

public static void DoMouseClick()
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}

将光标移动到你想要的地方:

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

public static void MoveCursorToPoint(int x, int y)
{
SetCursorPos(x, y);
}

关于c# - 如何以编程方式在 C# 中触发鼠标左键单击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2736965/

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