c# 模拟鼠标点击

来源:互联网 发布:疯狗雾化器口感数据 编辑:程序博客网 时间:2024/04/30 10:47
            const int MOUSEEVENTF_MOVE = 0x0001;      //移动鼠标 
            const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下 
            const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起 
            const int MOUSEEVENTF_RIGHTDOWN = 0x0008;// 模拟鼠标右键按下 
            const int MOUSEEVENTF_RIGHTUP = 0x0010;// 模拟鼠标右键抬起 
            const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;// 模拟鼠标中键按下 
            const int MOUSEEVENTF_MIDDLEUP = 0x0040;// 模拟鼠标中键抬起 
            const int MOUSEEVENTF_ABSOLUTE = 0x8000;// 标示是否采用绝对坐标 


            //HtmlElement el = webBrowser1.Document.GetElementById("snext");
            //HtmlElement el = webBrowser1.Document.GetElementById("su");
            HtmlElement el = GetMyEl("http://download.cnet.com/Teacher-s-Attach/3000-20415_4-12476080.html");
            if (el == null) return;
            el.ScrollIntoView(true);
            //el.ScrollTop = 0;
            
            Rectangle r = el.OffsetRectangle;


            int x=0;
            int y=0;
            if (r.Top > webBrowser1.Bottom)
                y = this.Location.Y + webBrowser1.Location.Y + webBrowser1.Bottom;
            else
                y = this.Location.Y + webBrowser1.Location.Y + r.Bottom;
            
            x=this.Location.X+webBrowser1.Location.X+r.Left;
            this.Text = "form location:" + this.Location.X + " " + this.Location.Y + " Webbrowser:" + webBrowser1.Left.ToString() + "   " +
                webBrowser1.Top.ToString() + "bottom" + webBrowser1.Bottom.ToString()
                + "   Html:" + r.Top.ToString() + "x+y" + x.ToString() + ":" + y.ToString(); ;
            
            //程序中我们直接调用mouse_event函数就可以了 
            //mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE,500, 100, 0, 0);


            SetCursorPos( 25+x,  y-15);


          
            //PostMessage(hButton, WM_LBUTTONDOWN, MK_LBUTTON, NULL);
            //模拟鼠标右键单击事件: 
            mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
            //这里是鼠标左键按下和松开两个事件的组合即一次单击: 
            //mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
0 0
原创粉丝点击