gpt4 book ai didi

c# - 在C#中的非事件窗口的某个位置模拟鼠标点击

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

这是原始问题,但它被认为是 java: Simulate mouse clicks at a certain position on inactive window in Java?

无论如何,我正在构建一个在后台运行的机器人。这个机器人需要我点击。当然,我希望能够在机器人运行时做其他事情。

所以我想知道是否可以在非事件窗口的某个位置模拟鼠标点击。

如果这是可能的,如果你们中的任何人能帮助我,我将不胜感激。

谢谢!

最佳答案

是的,这是可能的,这是我在以前的学校项目中使用的代码:

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

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

//This simulates a left mouse click
public static void LeftMouseClick(Point position)
{
Cursor.Position = position;
mouse_event(MOUSEEVENTF_LEFTDOWN, position.X, position.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, position.X, position.Y, 0, 0);
}

编辑: 似乎 mouse_event函数被 SendInput() 取代但它仍然有效(Windows 7 及更早版本)

关于c# - 在C#中的非事件窗口的某个位置模拟鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8242409/

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