C#产生鼠标单击事件
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
publicclass Form1 : Form
{
[DllImport("user32.dll",CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
publicstaticexternvoid mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons,
uint dwExtraInfo);
privateconstint MOUSEEVENTF_LEFTDOWN = 0x02;
privateconstint MOUSEEVENTF_LEFTUP = 0x04;
privateconstint MOUSEEVENTF_RIGHTDOWN = 0x08;
privateconstint MOUSEEVENTF_RIGHTUP = 0x10;
public Form1()
{
}
publicvoid 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
}
是调用user32.dll的api,在调用时需要将要模拟点击的位置和左键右键信息传给mouse_event方法。