Click here to Skip to main content
12,512,068 members (54,739 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET .NET4 Internet Explorer , +
Hey Guys,

I'm just working on an automation tool for IE. First thing is to start it through the script which works well, but now I want to catch Mouse Events. Currently I'm using SHDocVw and MSHTML, I also tried to work with
using System.Windows.Forms.WebBrowser;
but that confused me even more.

In practice: I want the IE to start and capture every link/button that was clicked with tag or name (at first simply through console output). It's not gonna be an invisible logging tool!!!

One test also tried to work with including JavaScript into the code, but I couldn't bring that to life either. If you have any idea on this, I'd be glad to read it.

My Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SHDocVw;
using mshtml;
using System.Windows.Forms;

namespace IETesting
    class EventHandlers
        public void OnDocumentComplete(object pDisp, ref object URL)
            Console.WriteLine("DocumentComplete fired!");
        public void OnNavigateComplete(object pDisp, ref object URL)
            Console.WriteLine("NavigateComplete2 fired!");
        public void OnMouseDown(IHTMLEventObj pEvtObj)
            Console.WriteLine("MouseDown fired!");
    class Program
        static void Main(String[] args)
            EventHandlers e = new EventHandlers();
            SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
            mshtml.HTMLDocument htmlDoc = new HTMLDocument();
            object Empty = 0;
            object URL = "";
            IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(e.OnDocumentComplete); // event that is actually fired
            IE.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(e.OnNavigateComplete); // event that is actually fired
            ((HTMLDocumentEvents2_Event)htmlDoc).onmousedown += new mshtml.HTMLDocumentEvents2_onmousedownEventHandler(e.OnMouseDown); // never triggered

            IE.Visible = true;
            IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);

I already spent hours and days searching the web so don't just point me to the first pseudo-solution you find on google. Don't even dare to point me to this article: Working With Microsoft.mshtml.dll and SHDocVw.dll - because really NOTHING here described seems to work in any way.

I hope you can help me since I'm pretty close to freaking out. ;-)

Thank you in advance!
Posted 8-Oct-12 23:32pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100