mouse_event函数如何用?

lcj_net 2013-01-21 02:01:10
已知控件webbrowser的句柄和和相对控件的位置(point),怎么调用mouse_event实现在该位置的鼠标点击操作。
...全文
476 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lcj_net 2013-01-24
  • 打赏
  • 举报
回复
用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); //鼠标左键的抬起
失落的神庙 2013-01-21
  • 打赏
  • 举报
回复
#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

lcj_net 2013-01-21
  • 打赏
  • 举报
回复
用sendmessage怎么实现呢?
失落的神庙 2013-01-21
  • 打赏
  • 举报
回复
引用 5 楼 lcj_net 的回复:
试了例子,但是鼠标点击位置怎么给啊,我的相对的point还需要换算吗?
百度 鼠标移动api
lcj_net 2013-01-21
  • 打赏
  • 举报
回复
试了例子,但是鼠标点击位置怎么给啊,我的相对的point还需要换算吗?
XBodhi. 2013-01-21
  • 打赏
  • 举报
回复
MSDN
lcj_net 2013-01-21
  • 打赏
  • 举报
回复
看了,还是没什么思路啊。

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧