0

嗨,我有 ac# 应用程序和一个嵌入式浏览器,它的任务是找到一个链接,然后右键单击它并单击属性!

鼠标以编程方式移动,所以我需要在右键菜单中找到属性!

你能帮我怎么做吗?

我尝试在右键单击后按“r”,但它在某些计算机上不起作用!

所以我需要通过移动鼠标来做到这一点!

这是我查找链接并右键单击的代码:

int x = getXoffset(link);
int y = getYoffset(link);
webBrowser1.Document.Window.ScrollTo(x, y);
Linker.Win32.POINT p2 = new Linker.Win32.POINT();
webBrowser1.Focus();
p2.x = webBrowser1.Left + 10;
p2.y = webBrowser1.Top + 5;
Linker.Win32.ClientToScreen(this.Handle, ref p2);
Linker.Win32.SetCursorPos(p2.x, p2.y);
MouseOperations.GetCursorPosition();

MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown);
MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown);
MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp);

欢迎在右键单击菜单上访问属性的任何其他想法

4

1 回答 1

0

使用此代码:

 [DllImport("user32.dll", SetLastError = true)]
        static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
        public static void PressKey(Keys key, bool up)
        {
            const int KEYEVENTF_EXTENDEDKEY = 0x1;
            const int KEYEVENTF_KEYUP = 0x2;
            if (up)
            {
                keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
            }
            else
            {
                keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://google.com");//Your link
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted); 
        }

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //Find your link and right click(automatically by your code)
            webBrowser1.Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);
        }

        void Document_MouseDown(object sender, HtmlElementEventArgs e)
        {
            if (e.MouseButtonsPressed == MouseButtons.Right)
            {
                Thread.Sleep(1000);
                PressKey(Keys.P, true);
                PressKey(Keys.P, false);
            }
        }
于 2012-08-29T17:26:18.483 回答