mouse_event函数如何用? 已知控件webbrowser的句柄和和相对控件的位置(point),怎么调用mouse_event实现在该位置的鼠标点击操作。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://chengengjie.blog.163.com/blog/static/126331397201071611358941/ http://www.cnblogs.com/icebutterfly/archive/2011/08/05/2128353.html 试了例子,但是鼠标点击位置怎么给啊,我的相对的point还需要换算吗? #region 鼠标API /// <summary> /// 鼠标移动 /// </summary> /// <param name="X">目标x坐标</param> /// <param name="Y">目标y坐标</param> /// <returns></returns> [DllImport("user32.dll")] public static extern bool SetCursorPos(int X, int Y); [DllImport("user32.dll")] private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); const int MMove = 0x0001; //移动鼠标 const int LeftDown = 0x0002; //模拟鼠标左键按下 const int LeftUp = 0x0004; //模拟鼠标左键抬起 const int RightDown = 0x0008;// 模拟鼠标右键按下 const int RightUp = 0x0010;// 模拟鼠标右键抬起 const int MiddleDown = 0x0020;// 模拟鼠标中键按下 const int MiddleUp = 0x0040;// 模拟鼠标中键抬起 const int XDown = 0x0080; const int XUp = 0x0100; const int Wheel = 0x0800; const int VirtualDesk = 0x4000; const int Absolute = 0x8000;// 标示是否采用绝对坐标 /// <summary> /// 鼠标左键点击 /// </summary> private void ClickMouse() { mouse_event(LeftDown, 0, 0, 0, 0); Thread.Sleep(200); mouse_event(LeftUp, 0, 0, 0, 0); } #endregion 用postmessage 的API方法解决了 [DllImport("user32.dll", EntryPoint = "PostMessage")] private static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);调用:相对坐标point(x,y) PostMessage(hwnd, 513, 1, p.X + 65536 * p.Y);//鼠标左键的按下 PostMessage(hwnd, 514, 0, p.X + 65536 * p.Y); //鼠标左键的抬起 数据库 表被锁 要做更新操作 一直超时 求解决方案 C#中打开文件问题 dep_user = session["dep_user"] 有错? DataGridView即时刷新计算列的问题 请问一个多客户端数据库插入问题。 如何在winform上点击某个按钮弹出某个网站的主页? 删除窗体上面控件时,为何控件相关的事件代码没有删除? 关于SQL语句的问题,请帮帮忙? 哪里有C# WinForm的经典例程? visual studio 2015 打开项目时卡住卡在“准备项目” 同一版本的c#源码为什么也要转换 静态类如何扩展方法
/// <summary>
/// 鼠标移动
/// </summary>
/// <param name="X">目标x坐标</param>
/// <param name="Y">目标y坐标</param>
/// <returns></returns>
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); const int MMove = 0x0001; //移动鼠标
const int LeftDown = 0x0002; //模拟鼠标左键按下
const int LeftUp = 0x0004; //模拟鼠标左键抬起
const int RightDown = 0x0008;// 模拟鼠标右键按下
const int RightUp = 0x0010;// 模拟鼠标右键抬起
const int MiddleDown = 0x0020;// 模拟鼠标中键按下
const int MiddleUp = 0x0040;// 模拟鼠标中键抬起
const int XDown = 0x0080;
const int XUp = 0x0100;
const int Wheel = 0x0800;
const int VirtualDesk = 0x4000;
const int Absolute = 0x8000;// 标示是否采用绝对坐标 /// <summary>
/// 鼠标左键点击
/// </summary>
private void ClickMouse()
{
mouse_event(LeftDown, 0, 0, 0, 0);
Thread.Sleep(200);
mouse_event(LeftUp, 0, 0, 0, 0);
}
#endregion
[DllImport("user32.dll", EntryPoint = "PostMessage")]
private static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);调用:相对坐标point(x,y)
PostMessage(hwnd, 513, 1, p.X + 65536 * p.Y);//鼠标左键的按下
PostMessage(hwnd, 514, 0, p.X + 65536 * p.Y); //鼠标左键的抬起