如何不使用鼠标进行虚拟鼠标单击C# [英] How to perform a Virtual Mouse click C# without using a mouse
本文介绍了如何不使用鼠标进行虚拟鼠标单击C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Windows应用程序进行点击,在不使用鼠标实(这样我就可以将其最小化)。就像一个机器人会表现。
I'd like to perform a click in a windows application, without using the real mouse (so I can minimize it). Much like a bot would behave.
我将如何做到这一点?
推荐答案
下面的代码是从这里 一个转贴:
The code below is a repost from here:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Form1 : Form
{
[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint 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 Form1()
{
}
public void DoMouseClick()
{
//Call the imported function with the cursor's current position
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
//...other code needed for the application
}
这篇关于如何不使用鼠标进行虚拟鼠标单击C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文