在 C# 中自动化鼠标点击
我对 winforms 和自动化非常陌生,想知道是否有一种简单的方法可以强制光标在 C# 中单击。我已经将光标移动到正确的位置,并且我想让它执行一次单击。是否有代码可以做到这一点,而不变得超级复杂。 (为了清楚起见,我在另一个应用程序中的按钮上自动单击鼠标,此时该应用程序已打开)
以下是我设置光标位置的方法:
Cursor.Position = new Point(x, y);Cursor.Position = new Point(x, y);代码>
I am very new to winforms and automation in general, and was wondering if there is a simple way to force the cursor to click in C#. I am already moving the cursor to the right spot, and I want to make it perform a click. Is there code that will do this, without getting super complicated. (for clarity, I am automating a mouseclick on a button in another application, which has been opened at this point)
Here is how I set the cursor position:
Cursor.Position = new Point(x, y);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你应该尝试 AutoIt v3 ,除非你特别绑定到 C#。它是为这种自动化而设计的。
例如:
I think you should try AutoIt v3 instead unless you specifically are bound to C#. It's designed for this kind of automation.
For example:
您需要通过
MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP
到mouse_event
函数。You will want to pass
MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP
to themouse_event
function.