由于某种特殊需求,我需要在winform程序中模拟鼠标点击事件,经过Google,终于找到了如下解决方案。
2013-03-07 15:57
417 查看
来自:http://outofmemory.cn/code-snippet/1708/how-winform-moni-shubiao-click-event
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# Win32API 模拟鼠标移动及点击事件
- Js 模拟鼠标点击事件
- C# Win32API 模拟鼠标移动及点击事件
- js 模拟鼠标点击事件
- 简单但是重复犯的错误(点击事件和鼠标经过事件的冲突)
- java swing 鼠标自动模拟点击事件
- js 模拟鼠标点击事件
- CSS 鼠标响应事件,鼠标经过CSS,鼠标移动CSS,鼠标点击CSS
- [python] 1、python鼠标点击、移动事件应用——写一个自动下载百度音乐的程序
- 编写一个组合鼠标事件和键盘事件的程序,该程序模拟一个电子白板,用户用鼠标在白板上画画,并通过键盘在上面写字
- 使用jQuery模拟鼠标点击a标签事件
- 使用JS或jQuery模拟鼠标点击a标签事件
- 用js模拟鼠标点击事件(事件触发)
- jquery如何在页面加载完成后模拟出一个鼠标点击事件?
- javascript 模拟的鼠标点击事件
- 使用JS或jQuery模拟鼠标点击a标签事件代码
- 关于BUTTON模拟FILE控件的点击事件的一揽子解决方案
- C# Win32API 模拟鼠标移动及点击事件
- 鼠标经过子元素触发mouseout,mouseover事件的解决方案
- 使用jQuery 模拟鼠标点击a标签事件 实现定位