Exemplo n.º 1
0
        public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int keyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
        {
            var ctrl  = modifiers.HasFlag(CefEventFlags.ControlDown);
            var shift = modifiers.HasFlag(CefEventFlags.ShiftDown);

            if (type == KeyType.KeyUp && ctrl && (keyCode == (int)Keys.F))
            {
                FindRequested?.Invoke();
            }

            if (type == KeyType.KeyUp && ((keyCode == (int)Keys.Add && ctrl) || (keyCode == (int)Keys.D1 && ctrl && shift)))
            {
                ZoomInRequested?.Invoke();
            }

            if (type == KeyType.KeyUp && (keyCode == (int)Keys.Subtract || keyCode == (int)Keys.OemMinus) && ctrl)
            {
                ZoomOutRequested?.Invoke();
            }

            if (type == KeyType.KeyUp && (keyCode == (int)Keys.D0 || keyCode == (int)Keys.NumPad0) && ctrl)
            {
                ZoomResetRequested?.Invoke();
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool IsReloadShortcut(KeyType type, int keyCode, CefEventFlags modifiers)
        {
            var f5   = keyCode == (int)Keys.F5;
            var r    = keyCode == (int)Keys.R;
            var ctrl = modifiers.HasFlag(CefEventFlags.ControlDown);

            return(type == KeyType.KeyUp && (f5 || ctrl && r));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts a combination of a virtual key code and a modifier key state into a string of one or more Unicode characters.
        /// </summary>
        /// <param name="virtualKey">The virtual key code that is to be translated.</param>
        /// <param name="modifiers">A bitwise combination of the <see cref="CefEventFlags"/> values.</param>
        /// <returns>The character resulting from the virtual key code being handled.</returns>
        public static char TranslateVirtualKey(VirtualKeys virtualKey, CefEventFlags modifiers)
        {
            XKeySym keysym = Linux.KeyInterop.VirtualKeyToXKeySym(virtualKey, modifiers.HasFlag(CefEventFlags.ShiftDown));

            if (keysym == XKeySym.None)
            {
                return(char.MinValue);
            }
            return(Linux.KeyInterop.XKeySymToChar(keysym));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Translates a virtual key to the corresponding native key code for the current keyboard.
        /// </summary>
        /// <param name="eventType">The key event type.</param>
        /// <param name="repeatCount">The repeat count for a message.</param>
        /// <param name="modifiers">A bitwise combination of the <see cref="CefEventFlags"/> values.</param>
        /// <param name="key">The virtual key.</param>
        /// <param name="isExtended">The extended key flag.</param>
        /// <returns>A native key code for the current keyboard.</returns>
        public static int GetNativeKeyCode(CefKeyEventType eventType, int repeatCount, VirtualKeys key, CefEventFlags modifiers, bool isExtended)
        {
            if (PlatformInfo.IsWindows)
            {
                return(GetWindowsNativeKeyCode(eventType, repeatCount, (byte)NativeMethods.MapVirtualKey((uint)key, MapVirtualKeyType.MAPVK_VK_TO_VSC), modifiers.HasFlag(CefEventFlags.AltDown), isExtended));
            }
            if (PlatformInfo.IsLinux)
            {
                return(GetLinuxNativeKeyCode(key, modifiers.HasFlag(CefEventFlags.ShiftDown)));
            }

            return(0);
        }
Exemplo n.º 5
0
        private static bool OnKeyDown(IWebBrowser browserControl, int windowsKeyCode, CefEventFlags modifiers)
        {
            var control = browserControl is CefSharp.WinForms.ChromiumWebBrowser formsBrowser
                    ? (FrameworkElement)formsBrowser.FindWpfHost()
                    : browserControl as CefSharp.Wpf.ChromiumWebBrowser;
            var window = control == null ? null : Window.GetWindow(control);

            if (window == null)
            {
                return(false);
            }

            var key = KeyInterop.KeyFromVirtualKey(windowsKeyCode);

            if (key == Key.Escape)
            {
                control.RemoveFocus();
                return(true);
            }

            return((modifiers.HasFlag(CefEventFlags.ControlDown) || modifiers.HasFlag(CefEventFlags.AltDown)) && ExecuteInputBinding(key, window));
        }
Exemplo n.º 6
0
        public bool OnKeyEvent(IWebBrowser browser, KeyType type, int code, CefEventFlags modifiers, bool isSystemKey)
        {
            // Handle keypress to display DevTools when needed.
            if (type.HasFlag(KeyType.KeyUp) &&
                (Keys)code == Keys.I &&
                modifiers.HasFlag(CefEventFlags.ControlDown) &&
                modifiers.HasFlag(CefEventFlags.ShiftDown))
            {
                this.Browser.ShowDevTools();
                return(true);
            }

            // Handle keypress to reload the page.
            if (type.HasFlag(KeyType.KeyUp) &&
                (Keys)code == Keys.R &&
                modifiers.HasFlag(CefEventFlags.ControlDown))
            {
                this.Browser.Reload();
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Converts the value of a UTF-16 encoded character into a native key code.
        /// </summary>
        /// <param name="c">The character.</param>
        /// <param name="repeatCount">The repeat count for a message.</param>
        /// <param name="modifiers">A bitwise combination of the <see cref="CefEventFlags"/> values.</param>
        /// <param name="isExtended">The extended key flag.</param>
        public static int GetNativeKeyCode(char c, int repeatCount, CefEventFlags modifiers, bool isExtended)
        {
            if (PlatformInfo.IsWindows)
            {
                return(GetWindowsNativeKeyCode(CefKeyEventType.Char, repeatCount,
                                               (byte)(WinApi.NativeMethods.VkKeyScan(c) & 0xFF),
                                               modifiers.HasFlag(CefEventFlags.AltDown), isExtended));
            }

            if (PlatformInfo.IsLinux)
            {
                return(GetLinuxNativeKeyCode(c));
            }

            throw new NotImplementedException();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Converts the specified virtual-key code into the current platform&apos;s
 /// native keycode (scancode).
 /// </summary>
 /// <param name="key">The virtual key.</param>
 /// <param name="modifiers">A bitwise combination of the <see cref="CefEventFlags"/> values.</param>
 /// <param name="extended">The extended key flag.</param>
 /// <returns>
 /// A native key code of virtual-key for the current keyboard. If there is no translation, the return value is zero.
 /// </returns>
 public virtual int VirtualKeyToNativeKeyCode(VirtualKeys key, CefEventFlags modifiers, bool extended)
 {
     if (PlatformInfo.IsWindows)
     {
         return(GetWindowsNativeKeyCode(key, extended));
     }
     if (PlatformInfo.IsLinux)
     {
         return(GetLinuxNativeKeyCode(key, modifiers.HasFlag(CefEventFlags.ShiftDown)));
     }
     if (PlatformInfo.IsMacOS)
     {
         return(GetMacOSNativeKeyCode(key, extended));
     }
     return(0);
 }
        bool IKeyboardHandler.OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
        {
            //    browserControl.Copy();

            /* double change = 0.1;
             *  Task<double> task = browser.GetZoomLevelAsync();
             *  task.ContinueWith(previous =>
             *  {
             *      if (previous.IsCompleted)
             *      {
             *          double currentLevel = previous.Result;
             *          browser.SetZoomLevel(currentLevel + change);
             *      }
             *      else
             *      {
             *          throw new InvalidOperationException("Unexpected failure of calling CEF->GetZoomLevelAsync", previous.Exception);
             *      }
             *  }, TaskContinuationOptions.ExecuteSynchronously);
             *  return true;*/

            //Debug.WriteLine("KeyType= {0} ,windowsKeyCode = {1} , modifiers={2}", type, windowsKeyCode, modifiers);
            if (modifiers.HasFlag(CefEventFlags.ControlDown) && windowsKeyCode == (int)Keys.Add)
            {
                _ctrlBrowser.tsZoomPlus_Click(this, EventArgs.Empty);
                return(true);
            }
            if (modifiers.HasFlag(CefEventFlags.ControlDown) && windowsKeyCode == (int)Keys.Subtract)
            {
                _ctrlBrowser.tsZoomMinus_Click(this, EventArgs.Empty);
                return(true);
            }
            if (modifiers == CefEventFlags.ControlDown && windowsKeyCode == (int)Keys.C)
            {
                _frmMain.last_command           = ContextMenuCommand.CMD_COPY;
                _frmMain.isCopyWithoutTranslate = false;
                browserControl.Copy();
                return(true);
            }
            else if (windowsKeyCode == (int)Keys.F2 && type != KeyType.Char)
            {
                _frmMain.last_command           = ContextMenuCommand.CMD_MY_COPY;
                _frmMain.isCopyWithoutTranslate = true;
                browserControl.Copy();
                return(true);
            }
            else
            {
                if (type != KeyType.Char)
                {
                    string kkey = string.Empty;
                    if (windowsKeyCode == (int)Keys.F1)
                    {
                        kkey = "f1";
                    }
                    //else if (windowsKeyCode == (int)Keys.F2) kkey = "f2";
                    else if (windowsKeyCode == (int)Keys.F3)
                    {
                        kkey = "f3";
                    }
                    else if (windowsKeyCode == (int)Keys.F4)
                    {
                        kkey = "f4";
                    }
                    else if (windowsKeyCode == (int)Keys.F5)
                    {
                        kkey = "f5";
                    }
                    else if (windowsKeyCode == (int)Keys.F6)
                    {
                        kkey = "f6";
                    }
                    else if (windowsKeyCode == (int)Keys.F7)
                    {
                        kkey = "f7";
                    }
                    else if (windowsKeyCode == (int)Keys.F8)
                    {
                        kkey = "f8";
                    }
                    else if (windowsKeyCode == (int)Keys.F9)
                    {
                        kkey = "f9";
                    }
                    else if (windowsKeyCode == (int)Keys.F10)
                    {
                        kkey = "f10";
                    }
                    else if (windowsKeyCode == (int)Keys.F11)
                    {
                        kkey = "f11";
                    }
                    else if (windowsKeyCode == (int)Keys.F12)
                    {
                        kkey = "f12";
                    }
                    MenuBrowser mb = GetMenuBrowserForShortcut(kkey);
                    if (mb != null)
                    {
                        _frmMain.last_command           = mb.Command;
                        _frmMain.isCopyWithoutTranslate = true;
                        browserControl.Copy();
                        return(true);
                    }
                }
            }
            isKeyboardShortcut = false;
            //true: Event is handeld
            return(false);
        }