Esempio n. 1
0
 private void showMagnifier()
 {
     if (formZoom == null)
     {
         formZoom      = new FormZoom();
         formZoom.Size = new System.Drawing.Size(magnifierWidth, magnifierHeigth);
         updateMagnifier();
     }
     else
     {
         formZoom.Close();
         formZoom = null;
     }
 }
Esempio n. 2
0
        private void timer_Tick(object sender, EventArgs e)
        {
            if (useCustomCursor)
            {
                formCursor.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
            }
            if (Cursor.Position != lastMousePosition && formZoom != null)
            {
                lastMousePosition = Cursor.Position;
                formZoom.Hide();
                updateMagnifier();
            }
            try
            {
                String keys = "";
                foreach (int i in Enum.GetValues(typeof(Keys)))
                {
                    if (GetAsyncKeyState(i) == -32767)
                    {
                        keys += Enum.GetName(typeof(Keys), i) + " ";
                    }
                }
                keys = keys.Trim();
                if (keys.StartsWith("ShiftKey "))
                {
                    keys = keys.Substring(9);
                }
                if (keys.StartsWith("Menu "))
                {
                    keys = keys.Substring(5);
                }

                if (keys != "")
                {
                    if (keys == keyMapLeft)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.X == 0)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                        }
                    }
                    else if (keys == keyMapUp)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X, Cursor.Position.Y - acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == 0)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                        }
                    }
                    else if (keys == keyMapRight)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.X == this.Size.Width - 1)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                        }
                    }
                    else if (keys == keyMapDown)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X, Cursor.Position.Y + acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == this.Size.Height - 1)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                        }
                    }
                    else if (keys == keyMapUpLeft)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y - acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == 0)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                            }
                            if (Cursor.Position.X == 0)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", -" + scrollSpeed + ");");
                        }
                    }
                    else if (keys == keyMapUpRight)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y - acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == 0)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                            }
                            if (Cursor.Position.X == this.Size.Width - 1)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", -" + scrollSpeed + ");");
                        }
                    }
                    else if (keys == keyMapDownLeft)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y + acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == this.Size.Height - 1)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                            }
                            if (Cursor.Position.X == 0)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", " + scrollSpeed + ");");
                        }
                    }
                    else if (keys == keyMapDownRight)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position         = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y + acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == this.Size.Height - 1)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                            }
                            if (Cursor.Position.X == this.Size.Width - 1)
                            {
                                webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                            }
                        }
                        else
                        {
                            webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", " + scrollSpeed + ");");
                        }
                    }
                    else if (keys == keyMapClick)
                    {
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                    }
                    else if (keys == keyMapDoubleClick)
                    {
                        doubleClick();
                    }
                    else if (keys == keyMapClose)
                    {
                        if (formPopup != null)
                        {
                            formPopup.Close();
                            formPopup = null;
                        }
                        else if (formZoom != null)
                        {
                            formZoom.Close();
                            formZoom = null;
                        }
                        else if (formKeyboardNavi != null)
                        {
                            formKeyboardNavi.Close();
                            formKeyboardNavi = null;
                        }
                        else if (formKeyboardSearch != null)
                        {
                            formKeyboardSearch.Close();
                            formKeyboardSearch = null;
                        }
                        else if (formFavourites != null)
                        {
                            formFavourites.Close();
                            formFavourites = null;
                        }
                        else if (formShortcuts != null)
                        {
                            formShortcuts.Close();
                            formShortcuts = null;
                        }
                        else if (formContextMenu != null)
                        {
                            formContextMenu.Close();
                            formContextMenu = null;
                        }
                        else
                        {
                            Process[] p = Process.GetProcessesByName("xbmc");
                            if (p.Count() > 0)
                            {
                                ShowWindow(p[0].MainWindowHandle, SW_SHOWMAXIMIZED);
                                SetForegroundWindow(p[0].MainWindowHandle);
                            }
                            Application.Exit();
                        }
                    }
                    else if (keys == keyMapZoomIn)
                    {
                        if (formZoom != null)
                        {
                            magnifierZoom++;
                            lastMousePosition = Cursor.Position;
                            formZoom.Hide();
                            updateMagnifier();
                        }
                        else
                        {
                            SendKeys.Send("^{ADD}");
                        }
                    }
                    else if (keys == keyMapZoomOut)
                    {
                        if (formZoom != null && magnifierZoom > 2)
                        {
                            magnifierZoom--;
                            lastMousePosition = Cursor.Position;
                            formZoom.Hide();
                            updateMagnifier();
                        }
                        else
                        {
                            SendKeys.Send("^{SUBTRACT}");
                        }
                    }
                    else if (keys == keyMapTAB)
                    {
                        pressTab();
                    }
                    else if (keys == keyMapESC)
                    {
                        pressEsc();
                    }
                    else if (keys == keyMapF5)
                    {
                        pressF5();
                    }
                    else if (keys == keyMapMagnifier)
                    {
                        showMagnifier();
                    }
                    else if (keys == keyMapNavigate)
                    {
                        enterUrl();
                    }
                    else if (keys == keyMapKeyboard)
                    {
                        showKeyboard();
                    }
                    else if (keys == keyMapFavourites)
                    {
                        showFavourites();
                    }
                    else if (keys == keyMapShortCuts)
                    {
                        showShortcuts();
                    }
                    else if (keys == keyMapToggleMouse)
                    {
                        mouseEnabled = !mouseEnabled;
                    }
                    else if (keys == keyMapContextMenu)
                    {
                        showContextMenu();
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 3
0
        public FormMain(String[] args)
        {
            InitializeComponent();

            mainTitle        = "";
            mainUrl          = "http://www.imdb.com/";
            userAgent        = "";
            minMouseSpeed    = 10;
            maxMouseSpeed    = 10;
            userDataFolder   = "";
            zoom             = 100;
            magnifierWidth   = 1280;
            magnifierHeigth  = 720;
            magnifierZoom    = 3;
            showPopups       = false;
            showScrollBar    = true;
            useCustomCursor  = true;
            customCursorSize = 64;
            mouseEnabled     = true;
            scrollSpeed      = 20;

            if (args.Length > 0)
            {
                userDataFolder = args[0].Replace("\"", "");
                mainTitle      = args[1].Replace("\"", "");
                mainUrl        = Uri.UnescapeDataString(args[2]);
                zoom           = Convert.ToInt32(args[3]);
                showPopups     = (args[4] == "yes");
                minMouseSpeed  = Convert.ToInt32(args[5]);
                maxMouseSpeed  = Convert.ToInt32(args[6]);
                String[] spl = args[7].Split('x');
                magnifierWidth   = Convert.ToInt32(spl[0]);
                magnifierHeigth  = Convert.ToInt32(spl[1]);
                useCustomCursor  = (args[8] == "true");
                customCursorSize = Convert.ToInt32(args[9]);
                showScrollBar    = (args[10] == "yes");
                scrollSpeed      = Convert.ToInt32(args[11]);
                userAgent        = args[12].Replace("\"", "");
            }

            //When using Windows
            String file  = userDataFolder + "\\keymap";
            String file2 = "C:\\xbmc_webbrowser\\keymap";

            if (File.Exists(file))
            {
                importKeymap(file);
            }
            //When using Wine
            else if (File.Exists(file2))
            {
                importKeymap(file2);
            }
            //Default key mapping
            else
            {
                keyMapUp          = "NumPad8";
                keyMapDown        = "NumPad2";
                keyMapLeft        = "NumPad4";
                keyMapRight       = "NumPad6";
                keyMapUpLeft      = "NumPad7";
                keyMapUpRight     = "NumPad9";
                keyMapDownLeft    = "NumPad1";
                keyMapDownRight   = "NumPad3";
                keyMapToggleMouse = "Multiply";
                keyMapClick       = "NumPad5";
                keyMapZoomIn      = "Add";
                keyMapZoomOut     = "Subtract";
                keyMapContextMenu = "Divide";
                keyMapClose       = "NumPad0";
                keyMapMagnifier   = "";
                keyMapFavourites  = "";
                keyMapShortCuts   = "";
                keyMapNavigate    = "";
                keyMapDoubleClick = "";
                keyMapKeyboard    = "";
                keyMapTAB         = "";
                keyMapESC         = "";
                keyMapF5          = "";
            }
            allKeys = new ArrayList();
            allKeys.Add(keyMapUp);
            allKeys.Add(keyMapDown);
            allKeys.Add(keyMapLeft);
            allKeys.Add(keyMapRight);
            allKeys.Add(keyMapUpLeft);
            allKeys.Add(keyMapUpRight);
            allKeys.Add(keyMapDownLeft);
            allKeys.Add(keyMapDownRight);
            allKeys.Add(keyMapClose);
            allKeys.Add(keyMapMagnifier);
            allKeys.Add(keyMapNavigate);
            allKeys.Add(keyMapZoomIn);
            allKeys.Add(keyMapZoomOut);
            allKeys.Add(keyMapClick);
            allKeys.Add(keyMapDoubleClick);
            allKeys.Add(keyMapKeyboard);
            allKeys.Add(keyMapFavourites);
            allKeys.Add(keyMapShortCuts);
            allKeys.Add(keyMapTAB);
            allKeys.Add(keyMapESC);
            allKeys.Add(keyMapToggleMouse);
            allKeys.Add(keyMapContextMenu);
            allKeys.Add(keyMapF5);

            formZoom           = null;
            formPopup          = null;
            formKeyboardNavi   = null;
            formKeyboardSearch = null;
            formFavourites     = null;
            formShortcuts      = null;
            formContextMenu    = null;

            lastMousePositionChange = 0;
            acceleration            = minMouseSpeed;
            this.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            webBrowser1.ScrollBarsEnabled = showScrollBar;
            if (useCustomCursor)
            {
                Cursor.Hide();
                formCursor = new FormCursor();
                String cursorPath = userDataFolder + "\\cursor.png";
                Bitmap oImage     = null;
                if (File.Exists(cursorPath))
                {
                    oImage = new Bitmap(cursorPath);
                }
                else
                {
                    oImage = new Bitmap(XBMC_WebBrowser.Properties.Resources.cursorBlue);
                }
                formCursor.BackgroundImage = oImage;
                formCursor.MinimumSize     = new System.Drawing.Size(32, 32);
                formCursor.Size            = new System.Drawing.Size(customCursorSize, customCursorSize);
                formCursor.Location        = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
                formCursor.Show();
            }
            if (userAgent == "")
            {
                webBrowser1.Navigate(mainUrl);
            }
            else
            {
                webBrowser1.Navigate(mainUrl, null, null, "User-Agent: " + userAgent);
            }
            nativeBrowser                  = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            nativeBrowser.NewWindow2      += nativeBrowser_NewWindow2;
            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
            mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
        }
Esempio n. 4
0
        private void timer_Tick(object sender, EventArgs e)
        {
            if (useCustomCursor && formCursor != null)
                formCursor.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);

            if ((Cursor.Position.X > lastMousePosition.X + 5 || Cursor.Position.X < lastMousePosition.X - 5
                || Cursor.Position.Y > lastMousePosition.Y + 5 || Cursor.Position.Y < lastMousePosition.Y - 5)
                && formZoom != null)
            {
                lastMousePosition = Cursor.Position;

                //formZoom.Hide();
                formZoom.Close();
                formZoom = null;

                //_timerUpdateMagnifier.Interval = 20;
                //_timerUpdateMagnifier.Tick += updateMagnifier_Tick;
                //_timerUpdateMagnifier.Enabled = false;
            }
        }
Esempio n. 5
0
 private void showMagnifier()
 {
     if (formZoom == null)
     {
         formZoom = new FormZoom();
         formZoom.Size = new System.Drawing.Size(magnifierWidth, magnifierHeigth);
         updateMagnifier();
     }
     else
     {
         formZoom.Close();
         formZoom = null;
     }
 }
Esempio n. 6
0
 private void HandleSpecialKeys(Keys keyData)
 {
     try
     {
         //String keys = "";
         //foreach (int i in Enum.GetValues(typeof(Keys)))
         //{
         //    if (GetAsyncKeyState(i) == -32767)
         //    {
         //        keys += Enum.GetName(typeof(Keys), i) + " ";
         //    }
         //}
         if (keyData != Keys.None)
         {
             if (XWKeys.getInstance().keyMapLeft.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.X > this.webBrowser1.Left)
                      Cursor.Position = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.X <= this.webBrowser1.Left)
                         webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
             }
             else if (XWKeys.getInstance().keyMapUp.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.Y > this.webBrowser1.Top)
                         Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - acceleration);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.Y <= this.webBrowser1.Top)
                         webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
             }
             else if (XWKeys.getInstance().keyMapRight.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.X < (this.webBrowser1.Left + this.webBrowser1.Size.Width) - customCursorSize)
                         Cursor.Position = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.X >= (this.webBrowser1.Left + this.webBrowser1.Size.Width) - customCursorSize)
                         webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
             }
             else if (XWKeys.getInstance().keyMapDown.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.Y < (this.webBrowser1.Top + this.webBrowser1.Size.Height) - customCursorSize)
                         Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + acceleration);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.Y >= (this.webBrowser1.Top + this.webBrowser1.Size.Height) - customCursorSize)
                         webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
             }
             else if (XWKeys.getInstance().keyMapUpLeft.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.X > this.webBrowser1.Left && Cursor.Position.Y > this.webBrowser1.Top)
                         Cursor.Position = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y - acceleration);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.Y <= this.webBrowser1.Top)
                         webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                     if (Cursor.Position.X <= this.webBrowser1.Left)
                         webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", -" + scrollSpeed + ");");
             }
             else if (XWKeys.getInstance().keyMapUpRight.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.X < (this.webBrowser1.Left + this.webBrowser1.Size.Width - customCursorSize) && Cursor.Position.Y > this.webBrowser1.Top)
                         Cursor.Position = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y - acceleration);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.Y <= this.webBrowser1.Top)
                         webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                     if (Cursor.Position.X >= (this.webBrowser1.Left + this.webBrowser1.Size.Width - customCursorSize))
                         webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", -" + scrollSpeed + ");");
             }
             else if (XWKeys.getInstance().keyMapDownLeft.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.X > this.webBrowser1.Left && Cursor.Position.Y < this.webBrowser1.Top + this.webBrowser1.Size.Height - customCursorSize)
                         Cursor.Position = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y + acceleration);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.Y >= this.webBrowser1.Top + this.webBrowser1.Size.Height - customCursorSize)
                         webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                     if (Cursor.Position.X <= this.webBrowser1.Left)
                         webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", " + scrollSpeed + ");");
             }
             else if (XWKeys.getInstance().keyMapDownRight.Contains(keyData))
             {
                 if (mouseEnabled)
                 {
                     setAcceleration();
                     if (Cursor.Position.Y < this.webBrowser1.Top+this.webBrowser1.Size.Height - customCursorSize && Cursor.Position.X < this.webBrowser1.Left + this.webBrowser1.Size.Width - customCursorSize)
                         Cursor.Position = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y + acceleration);
                     lastMousePositionChange = DateTime.Now.Ticks;
                     if (Cursor.Position.Y >= this.webBrowser1.Top+this.webBrowser1.Size.Height - customCursorSize)
                         webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                     if (Cursor.Position.X >= this.webBrowser1.Left + this.webBrowser1.Size.Width - customCursorSize)
                         webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                 }
                 else
                     webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", " + scrollSpeed + ");");
             }
             else if (XWKeys.getInstance().keyMapClick.Contains(keyData))
             {
                 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
             }
             else if (XWKeys.getInstance().keyMapDoubleClick.Contains(keyData))
             {
                 doubleClick();
             }
             else if (XWKeys.getInstance().keyMapClose.Contains(keyData))
             {
                 if (formPopup != null)
                 {
                     formPopup.Close();
                     formPopup = null;
                 }
                 else if (formZoom != null)
                 {
                     formZoom.Close();
                     formZoom = null;
                 }
                 else if (formKeyboardNavi != null)
                 {
                     formKeyboardNavi.Close();
                     formKeyboardNavi = null;
                 }
                 else if (formKeyboardSearch != null)
                 {
                     formKeyboardSearch.Close();
                     formKeyboardSearch = null;
                 }
                 else if (formFavourites != null)
                 {
                     formFavourites.Close();
                     formFavourites = null;
                 }
                 else if (formShortcuts != null)
                 {
                     formShortcuts.Close();
                     formShortcuts = null;
                 }
                 else if (formContextMenu != null)
                 {
                     formContextMenu.Close();
                     formContextMenu = null;
                 }
                 else
                 {
                     Process[] p = Process.GetProcessesByName("xbmc");
                     if (p.Count() > 0)
                     {
                         ShowWindow(p[0].MainWindowHandle, SW_SHOWMAXIMIZED);
                         SetForegroundWindow(p[0].MainWindowHandle);
                     }
                     Application.Exit();
                 }
             }
             else if (XWKeys.getInstance().keyMapZoomIn.Contains(keyData))
             {
                 if (formZoom != null)
                 {
                     magnifierZoom++;
                     lastMousePosition = Cursor.Position;
                     formZoom.Hide();
                     updateMagnifier();
                 }
                 else
                 {
                     activexZoom += activexZoomStep;
                     Zoom(activexZoom);
                     //SendKeys.Send("^{ADD}");
                 }
             }
             else if (XWKeys.getInstance().keyMapZoomOut.Contains(keyData))
             {
                 if (formZoom != null && magnifierZoom > 2)
                 {
                     magnifierZoom--;
                     lastMousePosition = Cursor.Position;
                     formZoom.Hide();
                     updateMagnifier();
                 }
                 else
                 {
                     activexZoom -= activexZoomStep;
                     Zoom(activexZoom);
                     //SendKeys.Send("^{SUBTRACT}");
                 }
             }
             else if (XWKeys.getInstance().keyMapTAB.Contains(keyData))
             {
                 pressTab();
             }
             else if (XWKeys.getInstance().keyMapESC.Contains(keyData))
             {
                 pressEsc();
             }
             else if (XWKeys.getInstance().keyMapF5.Contains(keyData))
             {
                 pressF5();
             }
             else if (XWKeys.getInstance().keyMapMagnifier.Contains(keyData))
             {
                 showMagnifier();
             }
             else if (XWKeys.getInstance().keyMapNavigate.Contains(keyData))
             {
                 enterUrl();
             }
             else if (XWKeys.getInstance().keyMapKeyboard.Contains(keyData))
             {
                 showKeyboard();
             }
             else if (XWKeys.getInstance().keyMapFavourites.Contains(keyData))
             {
                 showFavourites();
             }
             else if (XWKeys.getInstance().keyMapShortCuts.Contains(keyData))
             {
                 showShortcuts();
             }
             else if (XWKeys.getInstance().keyMapToggleMouse.Contains(keyData))
                 mouseEnabled = !mouseEnabled;
             else if (XWKeys.getInstance().keyMapContextMenu.Contains(keyData))
             {
                 showContextMenu();
             }
         }
     }
     catch (Exception ex)
     {
         //Console.WriteLine(ex.Message);
     }
 }
        public FormMain(String[] args)
        {
            InitializeComponent();

            mainTitle = "";
            mainUrl = "http://www.imdb.com/";
            userAgent = "";
            minMouseSpeed = 10;
            maxMouseSpeed = 10;
            userDataFolder = "";
            zoom = 100;
            magnifierWidth = 1280;
            magnifierHeigth = 720;
            magnifierZoom = 3;
            showPopups = false;
            showScrollBar = true;
            useCustomCursor = true;
            customCursorSize = 64;
            mouseEnabled = true;
            scrollSpeed = 20;

            if (args.Length > 0)
            {
                userDataFolder = args[0].Replace("\"", "");
                mainTitle = args[1].Replace("\"", "");
                mainUrl = Uri.UnescapeDataString(args[2]);
                zoom = Convert.ToInt32(args[3]);
                showPopups = (args[4] == "yes");
                minMouseSpeed = Convert.ToInt32(args[5]);
                maxMouseSpeed = Convert.ToInt32(args[6]);
                String[] spl = args[7].Split('x');
                magnifierWidth = Convert.ToInt32(spl[0]);
                magnifierHeigth = Convert.ToInt32(spl[1]);
                useCustomCursor = (args[8] == "true");
                customCursorSize = Convert.ToInt32(args[9]);
                showScrollBar = (args[10] == "yes");
                scrollSpeed = Convert.ToInt32(args[11]);
                userAgent = args[12].Replace("\"", "");
            }

            //When using Windows
            String file = userDataFolder + "\\keymap";
            String file2 = "C:\\xbmc_webbrowser\\keymap";
            if (File.Exists(file))
            {
                importKeymap(file);
            }
            //When using Wine
            else if (File.Exists(file2))
            {
                importKeymap(file2);
            }
            //Default key mapping
            else
            {
                keyMapUp = "NumPad8";
                keyMapDown = "NumPad2";
                keyMapLeft = "NumPad4";
                keyMapRight = "NumPad6";
                keyMapUpLeft = "NumPad7";
                keyMapUpRight = "NumPad9";
                keyMapDownLeft = "NumPad1";
                keyMapDownRight = "NumPad3";
                keyMapToggleMouse = "Multiply";
                keyMapClick = "NumPad5";
                keyMapZoomIn = "Add";
                keyMapZoomOut = "Subtract";
                keyMapContextMenu = "Divide";
                keyMapClose = "NumPad0";
                keyMapMagnifier = "";
                keyMapFavourites = "";
                keyMapShortCuts = "";
                keyMapNavigate = "";
                keyMapDoubleClick = "";
                keyMapKeyboard = "";
                keyMapTAB = "";
                keyMapESC = "";
                keyMapF5 = "";
            }
            allKeys = new ArrayList();
            allKeys.Add(keyMapUp);
            allKeys.Add(keyMapDown);
            allKeys.Add(keyMapLeft);
            allKeys.Add(keyMapRight);
            allKeys.Add(keyMapUpLeft);
            allKeys.Add(keyMapUpRight);
            allKeys.Add(keyMapDownLeft);
            allKeys.Add(keyMapDownRight);
            allKeys.Add(keyMapClose);
            allKeys.Add(keyMapMagnifier);
            allKeys.Add(keyMapNavigate);
            allKeys.Add(keyMapZoomIn);
            allKeys.Add(keyMapZoomOut);
            allKeys.Add(keyMapClick);
            allKeys.Add(keyMapDoubleClick);
            allKeys.Add(keyMapKeyboard);
            allKeys.Add(keyMapFavourites);
            allKeys.Add(keyMapShortCuts);
            allKeys.Add(keyMapTAB);
            allKeys.Add(keyMapESC);
            allKeys.Add(keyMapToggleMouse);
            allKeys.Add(keyMapContextMenu);
            allKeys.Add(keyMapF5);

            formZoom = null;
            formPopup = null;
            formKeyboardNavi = null;
            formKeyboardSearch = null;
            formFavourites = null;
            formShortcuts = null;
            formContextMenu = null;

            lastMousePositionChange = 0;
            acceleration = minMouseSpeed;
            this.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            webBrowser1.ScrollBarsEnabled = showScrollBar;
            if (useCustomCursor)
            {
                Cursor.Hide();
                formCursor = new FormCursor();
                String cursorPath = userDataFolder + "\\cursor.png";
                Bitmap oImage = null;
                if (File.Exists(cursorPath))
                {
                    oImage = new Bitmap(cursorPath);
                }
                else
                {
                    oImage = new Bitmap(XBMC_WebBrowser.Properties.Resources.cursorBlue);
                }
                formCursor.BackgroundImage = oImage;
                formCursor.MinimumSize = new System.Drawing.Size(32, 32);
                formCursor.Size = new System.Drawing.Size(customCursorSize, customCursorSize);
                formCursor.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
                formCursor.Show();
            }
            if (userAgent=="")
                webBrowser1.Navigate(mainUrl);
            else
                webBrowser1.Navigate(mainUrl, null, null, "User-Agent: " + userAgent);
            nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
            mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (useCustomCursor)
                formCursor.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
            if (Cursor.Position != lastMousePosition && formZoom != null)
            {
                lastMousePosition = Cursor.Position;
                formZoom.Hide();
                updateMagnifier();
            }
            try
            {
                String keys = "";
                foreach (int i in Enum.GetValues(typeof(Keys)))
                {
                    if (GetAsyncKeyState(i) == -32767)
                    {
                        keys += Enum.GetName(typeof(Keys), i) + " ";
                    }
                }
                keys = keys.Trim();
                if (keys.StartsWith("ShiftKey "))
                    keys = keys.Substring(9);
                if (keys.StartsWith("Menu "))
                    keys = keys.Substring(5);

                if (keys != "")
                {
                    if (keys == keyMapLeft)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.X == 0)
                                webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                    }
                    else if (keys == keyMapUp)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == 0)
                                webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                    }
                    else if (keys == keyMapRight)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.X == this.Size.Width - 1)
                                webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                    }
                    else if (keys == keyMapDown)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == this.Size.Height - 1)
                                webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                    }
                    else if (keys == keyMapUpLeft)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y - acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == 0)
                                webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                            if (Cursor.Position.X == 0)
                                webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", -" + scrollSpeed + ");");
                    }
                    else if (keys == keyMapUpRight)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y - acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == 0)
                                webBrowser1.Navigate("javascript:window.scrollBy(0, -" + scrollSpeed + ");");
                            if (Cursor.Position.X == this.Size.Width - 1)
                                webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", -" + scrollSpeed + ");");
                    }
                    else if (keys == keyMapDownLeft)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X - acceleration, Cursor.Position.Y + acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == this.Size.Height - 1)
                                webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                            if (Cursor.Position.X == 0)
                                webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", 0);");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(-" + scrollSpeed + ", " + scrollSpeed + ");");
                    }
                    else if (keys == keyMapDownRight)
                    {
                        if (mouseEnabled)
                        {
                            setAcceleration();
                            Cursor.Position = new Point(Cursor.Position.X + acceleration, Cursor.Position.Y + acceleration);
                            lastMousePositionChange = DateTime.Now.Ticks;
                            if (Cursor.Position.Y == this.Size.Height - 1)
                                webBrowser1.Navigate("javascript:window.scrollBy(0, " + scrollSpeed + ");");
                            if (Cursor.Position.X == this.Size.Width - 1)
                                webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", 0);");
                        }
                        else
                            webBrowser1.Navigate("javascript:window.scrollBy(" + scrollSpeed + ", " + scrollSpeed + ");");
                    }
                    else if (keys == keyMapClick)
                    {
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                    }
                    else if (keys == keyMapDoubleClick)
                    {
                        doubleClick();
                    }
                    else if (keys == keyMapClose)
                    {
                        if (formPopup != null)
                        {
                            formPopup.Close();
                            formPopup = null;
                        }
                        else if (formZoom != null)
                        {
                            formZoom.Close();
                            formZoom = null;
                        }
                        else if (formKeyboardNavi != null)
                        {
                            formKeyboardNavi.Close();
                            formKeyboardNavi = null;
                        }
                        else if (formKeyboardSearch != null)
                        {
                            formKeyboardSearch.Close();
                            formKeyboardSearch = null;
                        }
                        else if (formFavourites != null)
                        {
                            formFavourites.Close();
                            formFavourites = null;
                        }
                        else if (formShortcuts != null)
                        {
                            formShortcuts.Close();
                            formShortcuts = null;
                        }
                        else if (formContextMenu != null)
                        {
                            formContextMenu.Close();
                            formContextMenu = null;
                        }
                        else
                        {
                            Process[] p = Process.GetProcessesByName("xbmc");
                            if (p.Count() > 0)
                            {
                                ShowWindow(p[0].MainWindowHandle, SW_SHOWMAXIMIZED);
                                SetForegroundWindow(p[0].MainWindowHandle);
                            }
                            Application.Exit();
                        }
                    }
                    else if (keys == keyMapZoomIn)
                    {
                        if (formZoom != null)
                        {
                            magnifierZoom++;
                            lastMousePosition = Cursor.Position;
                            formZoom.Hide();
                            updateMagnifier();
                        }
                        else
                            SendKeys.Send("^{ADD}");
                    }
                    else if (keys == keyMapZoomOut)
                    {
                        if (formZoom != null && magnifierZoom>2)
                        {
                            magnifierZoom--;
                            lastMousePosition = Cursor.Position;
                            formZoom.Hide();
                            updateMagnifier();
                        }
                        else
                            SendKeys.Send("^{SUBTRACT}");
                    }
                    else if (keys == keyMapTAB)
                    {
                        pressTab();
                    }
                    else if (keys == keyMapESC)
                    {
                        pressEsc();
                    }
                    else if (keys == keyMapF5)
                    {
                        pressF5();
                    }
                    else if (keys == keyMapMagnifier)
                    {
                        showMagnifier();
                    }
                    else if (keys == keyMapNavigate)
                    {
                        enterUrl();
                    }
                    else if (keys == keyMapKeyboard)
                    {
                        showKeyboard();
                    }
                    else if (keys == keyMapFavourites)
                    {
                        showFavourites();
                    }
                    else if (keys == keyMapShortCuts)
                    {
                        showShortcuts();
                    }
                    else if (keys == keyMapToggleMouse)
                        mouseEnabled = !mouseEnabled;
                    else if (keys == keyMapContextMenu)
                    {
                        showContextMenu();
                    }
                }
            }
            catch
            {
            }
        }