示例#1
0
        public void OnWinKeyboardInput(uint code, IntPtr wParam, IntPtr lParam)
        {
            if (!Initalized || !KeyboardEnabled)
            {
                return;
            }

            int  keyCode = Marshal.ReadInt32(lParam);
            uint type    = (uint)wParam.ToInt32();

            if (Window.Browser.IsDisposed)
            {
                return;
            }

            Window.Browser.Invoke(new Action(() => {
                IntPtr handle = Win32Util.GetForegroundWindow();

                if (!HandleUtil.DesktopAreaHandle.Equals(handle))
                {
                    return;
                }

                CefSharp.IBrowserHost host = Window.Browser.GetBrowser().GetHost();

                switch (type)
                {
                case Win32Util.WM_KEYDOWN:
                    host.SendKeyEvent(new KeyEvent()
                    {
                        WindowsKeyCode       = keyCode,
                        FocusOnEditableField = true,
                        Type        = KeyEventType.KeyDown,
                        IsSystemKey = false
                    });
                    break;

                case Win32Util.WM_KEYUP:
                    host.SendKeyEvent(new KeyEvent()
                    {
                        WindowsKeyCode       = keyCode,
                        FocusOnEditableField = true,
                        Type        = KeyEventType.KeyUp,
                        IsSystemKey = false
                    });
                    break;

                default: break;
                }
            }));
        }
示例#2
0
        public void OnWinMouseInput(uint code, IntPtr wParam, IntPtr lParam)
        {
            if (!Initalized || !(MouseInteractionEnabled || MouseMovementEnabled))
            {
                return;
            }

            Win32Util.MOUSEHOOKSTRUCT input = Marshal.PtrToStructure <Win32Util.MOUSEHOOKSTRUCT>(lParam);
            uint type = (uint)wParam.ToInt32();

            if (Window.Browser.IsDisposed)
            {
                return;
            }

            Window.Browser.Invoke(new Action(() => {
                IntPtr handle = Win32Util.GetForegroundWindow();

                if (!HandleUtil.DesktopAreaHandle.Equals(handle))
                {
                    return;
                }

                CefSharp.IBrowserHost host = Window.Browser.GetBrowser().GetHost();

                if (MouseMovementEnabled)
                {
                    switch (type)
                    {
                    case Win32Util.WM_MOUSEMOVE:
                        host.SendMouseMoveEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), false);
                        break;

                    default: break;
                    }
                }

                if (MouseInteractionEnabled)
                {
                    switch (type)
                    {
                    case Win32Util.WM_LBUTTONDOWN:
                        host.SendFocusEvent(true);
                        host.SendMouseClickEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), CefSharp.MouseButtonType.Left, false, 1);
                        break;

                    case Win32Util.WM_LBUTTONUP:
                        host.SendMouseClickEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), CefSharp.MouseButtonType.Left, true, 1);
                        break;

                    case Win32Util.WM_MBUTTONDOWN:
                        host.SendFocusEvent(true);
                        host.SendMouseClickEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), CefSharp.MouseButtonType.Middle, false, 1);
                        break;

                    case Win32Util.WM_MBUTTONUP:
                        host.SendMouseClickEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), CefSharp.MouseButtonType.Middle, true, 1);
                        break;

                    case Win32Util.WM_RBUTTONDOWN:
                        host.SendFocusEvent(true);
                        host.SendMouseClickEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), CefSharp.MouseButtonType.Right, false, 1);
                        break;

                    case Win32Util.WM_RBUTTONUP:
                        host.SendMouseClickEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), CefSharp.MouseButtonType.Right, true, 1);
                        break;

                    case Win32Util.WM_MOUSEWHEEL:
                        int deltaY = input.mouseData >> 16;
                        host.SendMouseWheelEvent(new CefSharp.MouseEvent(input.pt.X, input.pt.Y, CefSharp.CefEventFlags.None), 0, deltaY);
                        break;

                    default: break;
                    }
                }
            }));
        }