namespace VideoBrowser.Controls.CefSharpBrowser.Handlers { using CefSharp; using CefSharp.Wpf; using System.Windows; using System.Windows.Forms; using System.Windows.Input; using VideoBrowser.Helpers; /// /// Defines the . /// public class CefKeyboardHandler : IKeyboardHandler { #region Constructors /// /// Initializes a new instance of the class. /// /// The host. internal CefKeyboardHandler(FrameworkElement host) { this.WebBrowser = host; } #endregion Constructors #region Properties /// /// Gets the WebBrowser. /// public FrameworkElement WebBrowser { get; } /// /// Gets or sets a value indicating whether IsFullScreen. /// private bool IsFullScreen { get; set; } #endregion Properties #region Methods /// /// The OnKeyEvent. /// /// The chromiumWebBrowser. /// The browser. /// The type. /// The windowsKeyCode. /// The nativeKeyCode. /// The modifiers. /// The isSystemKey. /// The . public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { return false; return this.WebBrowser.Dispatcher.Invoke(() => { var window = Window.GetWindow(this.WebBrowser); var routedEvent = UIElement.KeyDownEvent; var kb = Keyboard.PrimaryDevice; var ps = PresentationSource.FromDependencyObject(this.WebBrowser); var ts = 0; var key = KeyInterop.KeyFromVirtualKey(windowsKeyCode); var e = new System.Windows.Input.KeyEventArgs(kb, ps, ts, key) { RoutedEvent = routedEvent }; // WPF gets modifiers from PrimaryKeyboard only System.Diagnostics.Debug.WriteLine("Raising {0} {1}+{{{2}}}", routedEvent, key, Keyboard.Modifiers); this.WebBrowser.RaiseEvent(e); return e.Handled; }); } /// /// The OnPreKeyEvent. /// /// The browserControl. /// The browser. /// The type. /// The windowsKeyCode. /// The nativeKeyCode. /// The modifiers. /// The isSystemKey. /// The isKeyboardShortcut. /// The . public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; if ((Keys)windowsKeyCode == Keys.Escape) { chromiumWebBrowser.Invoke(delegate { ////var screenSize = Screen.FromControl(chromiumWebBrowser).Bounds.Size; ////bool fullScreen = screenSize == chromiumWebBrowser.Size; ////if (fullScreen) ////{ //// chromiumWebBrowser.DisplayHandler.OnFullscreenModeChange(browserControl, browser, false); ////} }); } return false; } #endregion Methods } }