WebBrowserControl KeyHooks (2 Viewers)

jwe

Portal Pro
November 17, 2011
64
57
Germany/Hessen/MKK
Home Country
Germany Germany
Hi,
i am currently developing a simple Plugin to display MCE-optimized VOD -sites in MediaPortal

Using System.Windows.Forms.Webbrowser Control this works great.

The only Problem I have, is that the website uses silverlight and i am not able to get any key event
so the user cant close (Use Escape-Key) my plugin - Only "ALT-F4" works to close mediaportal.

Any Idea on catching the KeyEvent of an webbrowser control if silverlight app is running?

Here is my Code so far:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;
using MediaPortal.Drawing;
using System;
using System.IO;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using MediaPortal.Dialogs;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaPortal.Common.Utils;
using MediaPortal.GUI.Library;
using MediaPortal.Configuration;
using MediaPortal.Dialogs;
using Point = System.Drawing.Point;

[assembly: CompatibleVersion("1.2.1.0", "1.2.1.0")]
namespace MaxDome
{
    [ComVisible(true)]
    public class Class1 : GUIWindow, ISetupForm
    {

        #region ISetupForm Members

        public override bool Init()
        {
            GUIGraphicsContext.form.Controls.Add(_webBrowser);
            _webBrowser.ObjectForScripting = GUIGraphicsContext.form;
            _webBrowser.MinimumSize = new System.Drawing.Size(20, 20);
            _webBrowser.Name = "webBrowser1";
            _webBrowser.Size = new System.Drawing.Size(512, 310);
            _webBrowser.TabIndex = 0;
            _webBrowser.ScrollBarsEnabled = false;
            _webBrowser.ScriptErrorsSuppressed = true;
            _webBrowser.IsWebBrowserContextMenuEnabled = false;
            _webBrowser.Visible = false;
            _webBrowser.KeyDown += new System.Windows.Forms.KeyEventHandler(_webBrowser_KeyDown);
            _webBrowser.KeyPress += new System.Windows.Forms.KeyPressEventHandler(_webBrowser_KeyPress);
            return Load(GUIGraphicsContext.Skin + @"\MaxDome.xml");
        }

        void _webBrowser_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            MessageBox.Show("KEYDOWN");
        }

        void _webBrowser_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            MessageBox.Show("KEYPRESS");
        }

        public override void DeInit()
        {
            _webBrowser.Visible = false;
            _webBrowser.Dispose();
            GUIGraphicsContext.form.Focus();
            base.DeInit();
        }



        // Returns the name of the plugin which is shown in the plugin menu
        public string PluginName()
        {
            return "MaxDome";
        }

        // Returns the description of the plugin is shown in the plugin menu
        public string Description()
        {
            return "Watch Tv on demand";
        }

        // Returns the author of the plugin which is shown in the plugin menu
        public string Author()
        {
            return "JanWe";
        }

        // show the setup dialog
        public void ShowPlugin()
        {
            MessageBox.Show("Nothing to configure, this is just an example");
        }

        // Indicates whether plugin can be enabled/disabled
        public bool CanEnable()
        {
            return true;
        }

        // Get Windows-ID
        public int GetWindowId()
        {
            // WindowID of windowplugin belonging to this setup
            // enter your own unique code
            return 9990;
        }

        // Indicates if plugin is enabled by default;
        public bool DefaultEnabled()
        {
            return true;
        }

        // indicates if a plugin has it's own setup screen
        public bool HasSetup()
        {
            return true;
        }

        /// <summary>
        /// If the plugin should have it's own button on the main menu of MediaPortal then it
        /// should return true to this method, otherwise if it should not be on home
        /// it should return false
        /// </summary>
        /// <param name="strButtonText">text the button should have</param>
        /// <param name="strButtonImage">image for the button, or empty for default</param>
        /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
        /// <param name="strPictureImage">subpicture for the button or empty for none</param>
        /// <returns>true : plugin needs it's own button on home
        /// false : plugin does not need it's own button on home</returns>

        public bool GetHome(out string strButtonText, out string strButtonImage,
          out string strButtonImageFocus, out string strPictureImage)
        {
            strButtonText = PluginName();
            strButtonImage = String.Empty;
            strButtonImageFocus = String.Empty;
            strPictureImage = String.Empty;
            return true;
        }

        // With GetID it will be an window-plugin / otherwise a process-plugin
        // Enter the id number here again
        public override int GetID
        {
            get
            {
                return 9990;
            }

            set
            {
            }
        }

        #endregion

        WebBrowser _webBrowser = new WebBrowser();

        protected override void OnPageLoad()
        {
            GUIWaitCursor.Init(); GUIWaitCursor.Show();
            _webBrowser.Location = new System.Drawing.Point(GUIGraphicsContext.OverScanWidth / 2 - 256, GUIGraphicsContext.OverScanHeight / 2 - 155);
            _webBrowser.Location=new Point(0,0);
            _webBrowser.Width = GUIGraphicsContext.Width;
            _webBrowser.Height = GUIGraphicsContext.Height;
            _webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(_webBrowser_DocumentCompleted);
            _webBrowser.Navigate("http://www.maxdome.de/mce/app/maxdome.html");
            base.OnPageLoad();
        }

        protected override void OnPageDestroy(int new_windowId)
        {
            base.OnPageDestroy(new_windowId);
            _webBrowser.Navigate("about:blank");
            _webBrowser.Visible = false;
            GUIGraphicsContext.form.Focus();

        }

        void _webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            _webBrowser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(_webBrowser_DocumentCompleted);
            if (_webBrowser.Url.AbsolutePath == "about:blank")
                return;
            try
            {
                _webBrowser.Visible = true;
            }
            catch { }
            finally
            {
                GUIWaitCursor.Dispose();
            }
        }
    }
}
 

Users who are viewing this thread

Top Bottom