Пример #1
0
        private void _BindDomEvent(DispHTMLDocument doc)
        {
            DOMEventHandler onclickHandler = new DOMEventHandler(doc, null);
            onclickHandler.NewEventHandlers += new DOMEvent(_click);
            doc.onmouseup = onclickHandler;

            DOMEventHandler onmouseoverHandler = new DOMEventHandler(doc, null);
            onmouseoverHandler.NewEventHandlers += new DOMEvent(_mouseover);
            doc.onmouseover = onmouseoverHandler;

            DOMEventHandler onmouseoutHandler = new DOMEventHandler(doc, null);
            onmouseoutHandler.NewEventHandlers += new DOMEvent(_mouseout);
            doc.onmouseout = onmouseoutHandler;

            DOMEventHandler onkeyupHandler = new DOMEventHandler(doc, null);
            onkeyupHandler.NewEventHandlers += new DOMEvent(_keyup);
            doc.onkeyup = onkeyupHandler;
        }
Пример #2
0
        //void keyHook_KeyDown(object sender, KeyEventArgs e)
        //{ }
        //void keyHook_KeyUp(object sender, KeyEventArgs e)
        //{ }
        //void keyHook_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    MessageBox.Show(e.KeyChar.ToString());
        //}
        //void mousehook_Click(object sender, MouseEventArgs e)
        //{
        //    if (UserBar.instance != null)
        //    {
        //        //Get Web Browser
        //        if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
        //        {
        //            IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;
        //            if (ActiveBrowser != null)
        //            {
        //                //Get the current document
        //                HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;
        //                if (htmlDoc != null)
        //                {
        //                    DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;
        //                    //Record the basic Url
        //                    string address = ActiveBrowser.LocationURL;
        //                    //Get
        //                    IHTMLElement activeElement = doc.activeElement;
        //                    if (activeElement.tagName != null)
        //                    {
        //                        //do something
        //                        //then do the right thing
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}
        //void mouseHook_MouseMove(object sender, MouseEventArgs e)
        //{ }
        //void mouseHook_MouseDown(object sender, MouseEventArgs e)
        //{ }
        //void mouseHook_MouseUp(object sender, MouseEventArgs e)
        //{
        //}
        //void mouseHook_MouseWheel(object sender, MouseEventArgs e)
        //{ }
        //[DllImport("user32.dll")]
        //static extern IntPtr GetForegroundWindow();
        //[DllImport("user32.dll")]
        //static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
        //private string GetActiveWindowTitle()
        //{
        //    const int nChars = 256;
        //    IntPtr handle = IntPtr.Zero;
        //    StringBuilder Buff = new StringBuilder(nChars);
        //    handle = GetForegroundWindow();
        //    if (GetWindowText(handle, Buff, nChars) > 0)
        //    {
        //        return Buff.ToString();
        //    }
        //    return null;
        //}
        //private const int WH_KEYBOARD_LL = 13;
        //protected const int WH_MOUSE_LL = 14;
        //protected const int WH_MOUSE = 7;
        //protected const int WH_KEYBOARD = 2;
        //protected const int WM_MOUSEMOVE = 0x200;
        //protected const int WM_LBUTTONDOWN = 0x201;
        //protected const int WM_RBUTTONDOWN = 0x204;
        //protected const int WM_MBUTTONDOWN = 0x207;
        //protected const int WM_LBUTTONUP = 0x202;
        //protected const int WM_RBUTTONUP = 0x205;
        //protected const int WM_MBUTTONUP = 0x208;
        //protected const int WM_LBUTTONDBLCLK = 0x203;
        //protected const int WM_RBUTTONDBLCLK = 0x206;
        //protected const int WM_MBUTTONDBLCLK = 0x209;
        //protected const int WM_MOUSEWHEEL = 0x020A;
        //protected const int WM_KEYDOWN = 0x100;
        //protected const int WM_KEYUP = 0x101;
        //protected const int WM_SYSKEYDOWN = 0x104;
        //protected const int WM_SYSKEYUP = 0x105;
        //protected const byte VK_SHIFT = 0x10;
        //protected const byte VK_CAPITAL = 0x14;
        //protected const byte VK_NUMLOCK = 0x90;
        //protected const byte VK_LSHIFT = 0xA0;
        //protected const byte VK_RSHIFT = 0xA1;
        //protected const byte VK_LCONTROL = 0xA2;
        //protected const byte VK_RCONTROL = 0x3;
        //protected const byte VK_LALT = 0xA4;
        //protected const byte VK_RALT = 0xA5;
        //protected const byte LLKHF_ALTDOWN = 0x20;
        //private static LowLevelMouseProc _proc = HookCallback;
        //private static IntPtr _hookID = IntPtr.Zero;
        //private static IntPtr SetHook(LowLevelMouseProc proc)
        //{
        //    using (Process curProcess = Process.GetCurrentProcess())
        //    using (ProcessModule curModule = curProcess.MainModule)
        //    {
        //        IntPtr handle = GetModuleHandle(curModule.ModuleName);
        //        IntPtr ret = SetWindowsHookEx(WH_MOUSE_LL, proc,
        //            handle, 0);
        //        //MessageBox.Show(Marshal.GetLastWin32Error().ToString());
        //        return ret;
        //    }
        //}
        //private delegate IntPtr LowLevelMouseProc(
        //    int nCode, IntPtr wParam, IntPtr lParam);
        //private static IntPtr HookCallback(
        //    int nCode, IntPtr wParam, IntPtr lParam)
        //{
        //    if (nCode >= 0 && wParam == (IntPtr)WM_LBUTTONUP)
        //    {
        //        int vkCode = Marshal.ReadInt32(lParam);
        //        //Console.WriteLine((Keys)vkCode);
        //        if (UserBar.instance != null)
        //        {
        //            //Get Web Browser
        //            if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
        //            {
        //                IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;
        //                if (ActiveBrowser != null)
        //                {
        //                    //Get the current document
        //                    HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;
        //                    if (htmlDoc != null)
        //                    {
        //                        DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;
        //                        //Record the basic Url
        //                        string address = ActiveBrowser.LocationURL;
        //                        //Get
        //                        IHTMLElement activeElement = doc.activeElement;
        //                        if (activeElement != null)
        //                        {
        //                            MessageBox.Show(activeElement.tagName);
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    return CallNextHookEx(_hookID, nCode, wParam, lParam);
        //}
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr SetWindowsHookEx(int idHook,
        //    LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //[return: MarshalAs(UnmanagedType.Bool)]
        //private static extern bool UnhookWindowsHookEx(IntPtr hhk);
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
        //    IntPtr wParam, IntPtr lParam);
        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr GetModuleHandle(string lpModuleName);
        //void HookMouseUp(object sender, Microsoft.Win32.MouseHookEventArgs e)
        //{
        //    if (UserBar.instance != null)
        //    {
        //        //Get Web Browser
        //        if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
        //        {
        //            IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;
        //            if (ActiveBrowser != null)
        //            {
        //                //Get the current document
        //                HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;
        //                if (htmlDoc != null)
        //                {
        //                    DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;
        //                    //Record the basic Url
        //                    string address = ActiveBrowser.LocationURL;
        //                    //Get
        //                    IHTMLElement activeElement = doc.activeElement;
        //                    if (activeElement != null)
        //                    {
        //                        MessageBox.Show(activeElement.tagName);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}
        void Recorder_OnDocumentComplete(object pDisp, ref object url)
        {
            if (UserBar.instance != null)
            {
                //Get Web Browser
                if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
                {
                    IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;

                    if (ActiveBrowser != null)
                    {

                        //Get the current document
                        HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;

                        DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;

                        //Record the basic Url
                        string address = ActiveBrowser.LocationURL;

                        if (htmlDoc != null)
                        {
                            //Bind events
                            DOMEventHandler onclickhandler = new DOMEventHandler(doc, null);
                            onclickhandler.NewEventHandlers += new DOMEvent(DOMEventMethods._click);
                            doc.onclick = onclickhandler;

                            DOMEventHandler onclickhandler1 = new DOMEventHandler(doc, doc.onclick);
                            onclickhandler1.NewEventHandlers += new DOMEvent(DOMEventMethods._link_click);
                            doc.onmouseup = onclickhandler1;

                            //Bind Href Click
                            //foreach (mshtml.HTMLAnchorElement link in htmlDoc.anchors)
                            //{

                            //    ((HTMLAnchorEvents_Event)link).onmouseup += new HTMLAnchorEvents_onmouseupEventHandler(() =>
                            //    {
                            //        DOMEventMethods._link_click(link);
                            //        //return true;
                            //    });
                            //}

                            //Bind IFrame events
                            //IHTMLElementCollection elems = htmlDoc.getElementsByTagName("iframe");
                            //foreach (IHTMLElement elem in elems)
                            //{
                            //    HTMLFrameElement frm = (HTMLFrameElement)elem;
                            //    DispHTMLDocument frm_doc = (DispHTMLDocument)((SHDocVw.IWebBrowser2)frm).Document;
                            //    DOMEventHandler onclickfrmhandler = new DOMEventHandler(frm_doc);
                            //    onclickfrmhandler.Handler += new DOMEvent(DOMEventMethods._click);
                            //    (frm as DispHTMLDocument).onclick = onclickfrmhandler;
                            //}

                        }
                    }
                }
            }
        }