Beispiel #1
0
        // key events
        // this is not complete

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (cfxBrowser != null)
            {
                var k = new CfxKeyEvent();
                k.WindowsKeyCode = e.KeyChar;
                k.Type           = CfxKeyEventType.Char;
                switch (Control.ModifierKeys)
                {
                case Keys.Alt:
                    k.Modifiers = (uint)CfxEventFlags.AltDown;
                    break;

                case Keys.Shift:
                    k.Modifiers = (uint)CfxEventFlags.ShiftDown;
                    break;

                case Keys.Control:
                    k.Modifiers = (uint)CfxEventFlags.ControlDown;
                    break;
                }
                cfxBrowser.Host.SendKeyEvent(k);
            }
            base.OnKeyPress(e);
        }
Beispiel #2
0
        // key events
        // this is not complete

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (browser == null)
            {
                return;
            }
            //Console.WriteLine (e.KeyChar);
            if (e.KeyChar == 7)
            {
                // ctrl+g - load google so we have a page with text input
                browser.MainFrame.LoadUrl("https://www.baidu.com");
            }
            else
            {
                if (!e.Handled)
                {
                    var k = new CfxKeyEvent();
                    k.WindowsKeyCode      = e.KeyChar;
                    k.Character           = (short)e.KeyChar;
                    k.Type                = CfxKeyEventType.Char;
                    k.UnmodifiedCharacter = (short)e.KeyChar;
                    browser.Host.SendKeyEvent(k);

                    e.Handled = true;
                }
            }
        }
 protected override void Operation(HtmlTextureWrapper wrapper)
 {
     foreach (var ke in Down)
     {
         var cke = new CfxKeyEvent
         {
             Type           = CfxKeyEventType.Keydown,
             Character      = (short)ke.KeyChar[0],
             WindowsKeyCode = ke.KeyCode,
             NativeKeyCode  = ke.KeyCode
         };
         wrapper.Browser.Host.SendKeyEvent(cke);
     }
     foreach (var ke in Up)
     {
         var cke = new CfxKeyEvent
         {
             Type           = CfxKeyEventType.Keydown,
             Character      = (short)ke.KeyChar[0],
             WindowsKeyCode = ke.KeyCode,
             NativeKeyCode  = ke.KeyCode
         };
         wrapper.Browser.Host.SendKeyEvent(cke);
     }
 }
Beispiel #4
0
        // key events
        // this is not complete

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            var k = new CfxKeyEvent();

            k.WindowsKeyCode = e.KeyChar;
            k.Type           = CfxKeyEventType.Char;
            browser.Host.SendKeyEvent(k);
        }
Beispiel #5
0
        public void Inject(Key keyToInject)
        {
            var cxKeyEvent = new CfxKeyEvent()
            {
                WindowsKeyCode = (int)keyToInject
            };

            _ChromiumWebBrowser.Browser.Host.SendKeyEvent(cxKeyEvent);
        }
        public void Inject(Key keyToInject) 
        {
            var cxKeyEvent = new CfxKeyEvent() 
            {
                WindowsKeyCode = (int) keyToInject
            };

            _ChromiumWebBrowser.Browser.Host.SendKeyEvent(cxKeyEvent);
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            var j = new CfxKeyEvent();

            j.WindowsKeyCode = e.KeyValue;
            j.Character      = (short)e.KeyValue;
            j.Type           = CfxKeyEventType.Keydown;

            Browser.Host.SendKeyEvent(j);
        }
        // key events
        // this is not complete

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (e.KeyChar == 7)
            {
                // ctrl+g - load google so we have a page with text input
                browser.MainFrame.LoadUrl("https://www.google.com");
            }
            else
            {
                var k = new CfxKeyEvent();
                k.WindowsKeyCode = e.KeyChar;
                k.Type           = CfxKeyEventType.Char;
                browser.Host.SendKeyEvent(k);
            }
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
            case Keys.Down:
            case Keys.Left:
            case Keys.Right:
            case Keys.Up:
            {
                var j = new CfxKeyEvent();
                j.WindowsKeyCode = (int)keyData;
                j.Type           = CfxKeyEventType.RawKeydown;
                Browser.Host.SendKeyEvent(j);
                return(true);
            }

            default:
            {
                return(base.ProcessCmdKey(ref msg, keyData));
            }
            }
        }
Beispiel #10
0
        public override void Load()
        {
            Instance = this;
            effect   = GetEffect("Effects/BGRtoRGB");

            Scheduler.EnqueueMessage(() =>
            {
                Platform.Current.SetWindowUnicodeTitle(Main.instance.Window, Titles[Main.rand.Next(Titles.Length)]);

                if (!CfxRuntime.LibrariesLoaded)
                {
                    string path = CfxRuntime.PlatformArch == CfxPlatformArch.x64 ? "x64" : "x86";
                    CfxRuntime.LibCefDirPath = Path.Combine(Config.CefCfxPath, path);
                    CfxRuntime.LibCfxDirPath = Path.Combine(Config.CefCfxPath, path);
                }

                var exitCode = CfxRuntime.ExecuteProcess();
                if (exitCode >= 0)
                {
                    typeof(ModLoader).InvokeMethod <object>("DisableMod", Name);
                }

                var settings = new CfxSettings
                {
                    WindowlessRenderingEnabled = true,
                    NoSandbox        = true,
                    ResourcesDirPath = Config.ResourcesPath,
                    LocalesDirPath   = Path.Combine(Config.ResourcesPath, "locales"),
                    CachePath        = Config.CachePath
                };
                settings.MultiThreadedMessageLoop = true;

                CfxApp app = new CfxApp();
                app.OnBeforeCommandLineProcessing += (s, e) =>
                {
                    e.CommandLine.AppendSwitch("single-process");
                    e.CommandLine.AppendSwitch("disable-gpu");
                    e.CommandLine.AppendSwitch("disable-gpu-compositing");
                    e.CommandLine.AppendSwitch("disable-gpu-vsync");
                    e.CommandLine.AppendSwitchWithValue("enable-media-stream", "1");
                };

                if (!CfxRuntime.Initialize(settings, app))
                {
                    typeof(ModLoader).InvokeMethod <object>("DisableMod", Name);
                }

                GUI         = BaseLibrary.Utility.Utility.SetupGUI <TestUI>();
                GUI.Visible = true;
            });

            void UpdateMouseEvent()
            {
                FocusedBrowser.mouseEvent.Modifiers = Utility.GetModifiers();
                FocusedBrowser.mouseEvent.X         = FocusedBrowser.RelativeMousePosition.X;
                FocusedBrowser.mouseEvent.Y         = FocusedBrowser.RelativeMousePosition.Y;
            }

            InputInterceptor.InterceptInput += () => FocusedBrowser != null;

            InputInterceptor.OnMouseMove += (x, y, modifiers) =>
            {
                PlayerInput.MouseX = x;
                PlayerInput.MouseY = y;

                Main.lastMouseX = Main.mouseX;
                Main.lastMouseY = Main.mouseY;
                Main.mouseX     = PlayerInput.MouseX;
                Main.mouseY     = PlayerInput.MouseY;

                typeof(PlayerInput).SetValue("_originalMouseX", Main.mouseX);
                typeof(PlayerInput).SetValue("_originalMouseY", Main.mouseY);
                typeof(PlayerInput).SetValue("_originalLastMouseX", Main.lastMouseX);
                typeof(PlayerInput).SetValue("_originalLastMouseY", Main.lastMouseY);

                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseMoveEvent(FocusedBrowser.mouseEvent, false);
            };
            InputInterceptor.OnMouseWheel += (delta, modifiers) =>
            {
                PlayerInput.ScrollWheelValue = PlayerInput.ScrollWheelValueOld;

                bool shiftDown = (modifiers & 4) != 0;

                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseWheelEvent(FocusedBrowser.mouseEvent, shiftDown ? delta : 0, shiftDown ? 0 : delta);
            };

            InputInterceptor.OnLeftMouseDown += (clickCount, modifiers) =>
            {
                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseClickEvent(FocusedBrowser.mouseEvent, CfxMouseButtonType.Left, false, clickCount);
            };
            InputInterceptor.OnLeftMouseUp += (clickCount, modifiers) =>
            {
                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseClickEvent(FocusedBrowser.mouseEvent, CfxMouseButtonType.Left, true, clickCount);
            };

            InputInterceptor.OnRightMouseDown += (clickCount, modifiers) =>
            {
                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseClickEvent(FocusedBrowser.mouseEvent, CfxMouseButtonType.Right, false, clickCount);
            };
            InputInterceptor.OnRightMouseUp += (clickCount, modifiers) =>
            {
                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseClickEvent(FocusedBrowser.mouseEvent, CfxMouseButtonType.Right, true, clickCount);
            };

            InputInterceptor.OnMiddleMouseDown += (clickCount, modifiers) =>
            {
                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseClickEvent(FocusedBrowser.mouseEvent, CfxMouseButtonType.Middle, false, clickCount);
            };
            InputInterceptor.OnMiddleMouseUp += (clickCount, modifiers) =>
            {
                UpdateMouseEvent();
                FocusedBrowser.BrowserHost.SendMouseClickEvent(FocusedBrowser.mouseEvent, CfxMouseButtonType.Middle, true, clickCount);
            };

            InputInterceptor.OnKeyChar += (key, modifiers) =>
            {
                if (key == (int)Utility.Keys.LMenu || key == (int)Utility.Keys.RMenu)
                {
                    return;
                }

                CfxKeyEvent keyEvent = new CfxKeyEvent
                {
                    WindowsKeyCode       = key,
                    Type                 = CfxKeyEventType.Char,
                    IsSystemKey          = false,
                    Modifiers            = Utility.GetModifiers(),
                    FocusOnEditableField = 1
                };

                FocusedBrowser.BrowserHost.SendKeyEvent(keyEvent);
            };
            InputInterceptor.OnKeyDown += (key, modifiers, systemKey) =>
            {
                if (key == (int)Utility.Keys.LMenu || key == (int)Utility.Keys.RMenu)
                {
                    return;
                }

                CfxKeyEvent keyEvent = new CfxKeyEvent
                {
                    WindowsKeyCode       = key,
                    Type                 = CfxKeyEventType.Keydown,
                    IsSystemKey          = systemKey,
                    Modifiers            = Utility.GetModifiers(),
                    FocusOnEditableField = 1
                };

                FocusedBrowser.BrowserHost.SendKeyEvent(keyEvent);
            };
            InputInterceptor.OnKeyUp += (key, modifiers, systemKey) =>
            {
                if (key == (int)Utility.Keys.LMenu || key == (int)Utility.Keys.RMenu)
                {
                    return;
                }

                CfxKeyEvent keyEvent = new CfxKeyEvent
                {
                    WindowsKeyCode       = key,
                    Type                 = CfxKeyEventType.Keyup,
                    IsSystemKey          = systemKey,
                    Modifiers            = Utility.GetModifiers(),
                    FocusOnEditableField = 1
                };

                FocusedBrowser.BrowserHost.SendKeyEvent(keyEvent);
            };
        }
        //called when data for any output pin is requested
        public void Update(int SpreadMax)
        {
            if (this.FTextureOutput[0] == null)
            {
                this.FTextureOutput[0] = new DX11Resource <DX11DynamicTexture2D>();
            }

            if (!init)
            {
                width  = DEFAULT_WIDTH;
                height = DEFAULT_HEIGHT;

                lifeSpanHandler = new CfxLifeSpanHandler();
                lifeSpanHandler.OnAfterCreated += lifeSpanHandler_OnAfterCreated;
                lifeSpanHandler.OnBeforePopup  += lifeSpanHandler_OnBeforePopup;

                renderHandler                    = new CfxRenderHandler();
                renderHandler.GetViewRect       += renderHandler_GetViewRect;
                renderHandler.GetRootScreenRect += renderHandler_GetRootScreenRect;
                renderHandler.OnPaint           += renderHandler_OnPaint;

                loadHandler                       = new CfxLoadHandler();
                loadHandler.OnLoadError          += loadHandler_OnLoadError;
                loadHandler.OnLoadingStateChange += loadHandler_OnLoadingStateChange;

                requestHandler = new CfxRequestHandler();
                requestHandler.OnBeforeBrowse       += requestHandler_OnBeforeBrowse;
                requestHandler.OnBeforeResourceLoad += requestHandler_OnBeforeResourceLoad;


                displayHandler = new CfxDisplayHandler();
                displayHandler.OnConsoleMessage += displayHandler_OnConsoleMessage;
                client = new CfxClient();
                client.GetLifeSpanHandler += (sender, e) => e.SetReturnValue(lifeSpanHandler);
                client.GetRenderHandler   += (sender, e) => e.SetReturnValue(renderHandler);
                client.GetLoadHandler     += (sender, e) => e.SetReturnValue(loadHandler);
                client.GetRequestHandler  += (sender, e) => e.SetReturnValue(requestHandler);;
                client.GetDisplayHandler  += (sender, e) => e.SetReturnValue(displayHandler);;



                settings = new CfxBrowserSettings();
                settings.WindowlessFrameRate = 60;
                settings.Webgl                       = CfxState.Enabled;
                settings.Plugins                     = CfxState.Enabled;
                settings.ApplicationCache            = CfxState.Enabled;
                settings.CaretBrowsing               = CfxState.Enabled;
                settings.Javascript                  = CfxState.Enabled;
                settings.FileAccessFromFileUrls      = CfxState.Enabled;
                settings.UniversalAccessFromFileUrls = CfxState.Enabled;
                settings.WebSecUrity                 = CfxState.Disabled;

                visitor        = new CfxStringVisitor();
                visitor.Visit += visitor_Visit;

                // set path to js
                string lpPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "livepage");


                LIVEPAGE_LOAD_FUNC =
                    File.ReadAllText(Path.Combine(lpPath, "load.js")) +
                    File.ReadAllText(Path.Combine(lpPath, "live_resource.js")) +
                    File.ReadAllText(Path.Combine(lpPath, "livepage.js"));

                LIVEPAGE_UNLOAD_FUNC = File.ReadAllText(Path.Combine(lpPath, "unload.js"));

                mouseEvent = new CfxMouseEvent();
                keyCode    = new List <int>();

                createBrowser = true;
                invalidate    = true;
                init          = true;
            }

            if (FTransparentIn.IsChanged)
            {
                createBrowser = true;
            }

            if (createBrowser)
            {
                var windowInfo = new CfxWindowInfo();
                windowInfo.SetAsWindowless(FTransparentIn[0]);
                //windowInfo.WindowlessRenderingEnabled = true;
                //windowInfo.TransparentPaintingEnabled = false;

                if (browser != null)
                {
                    browser.Host.CloseBrowser(true);
                    browser = null;
                }

                CfxBrowserHost.CreateBrowser(windowInfo, client, "", settings, null);

                createBrowser = false;
            }

            if (FMethodIn.IsChanged)
            {
                if (method == null || method.Length != FMethodIn.SliceCount)
                {
                    method = new bool[FMethodIn.SliceCount];
                }
                FResultOut.SliceCount = FMethodIn.SliceCount;
                FMethodOut.SliceCount = FMethodIn.SliceCount;
            }

            if (FLivePageIn.IsChanged)
            {
                ExecuteJavascript(FLivePageIn[0] ? LIVEPAGE_LOAD_FUNC : LIVEPAGE_UNLOAD_FUNC);
            }

            if (FZoomLevelIn.IsChanged)
            {
                zoomLevel = VMath.Map(FZoomLevelIn[0], 0, 1, 0, 10, TMapMode.Clamp);
            }

            for (int i = 0; i < FMethodOut.SliceCount; i++)
            {
                FMethodOut[i] = method[i];
                method[i]     = false;
            }

            if (browser != null)
            {
                if (FShowDevToolsIn.IsChanged && FShowDevToolsIn[0])
                {
                    CfxWindowInfo windowInfo = new CfxWindowInfo();

                    windowInfo.Style        = WindowStyle.WS_OVERLAPPEDWINDOW | WindowStyle.WS_CLIPCHILDREN | WindowStyle.WS_CLIPSIBLINGS | WindowStyle.WS_VISIBLE;
                    windowInfo.ParentWindow = IntPtr.Zero;
                    windowInfo.WindowName   = "DevTools";
                    windowInfo.X            = 200;
                    windowInfo.Y            = 200;
                    windowInfo.Width        = 800;
                    windowInfo.Height       = 600;

                    browser.Host.ShowDevTools(windowInfo, new CfxClient(), new CfxBrowserSettings(), null);
                }


                // mouse
                if (FTouchIn.IsChanged && FTouchIn.SliceCount > 0)
                {
                    mouseEvent.X = (int)VMath.Map(FTouchIn[0].x, -1, 1, 0, width, TMapMode.Float);
                    mouseEvent.Y = (int)VMath.Map(FTouchIn[0].y, 1, -1, 0, height, TMapMode.Float);

                    if (!isTouch)
                    {
                        browser.Host.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, false, 1);
                    }
                    else
                    {
                        browser.Host.SendMouseMoveEvent(mouseEvent, false);
                    }
                    isTouch = true;
                }
                if (isTouch && FTouchIn.SliceCount == 0)
                {
                    browser.Host.SendMouseClickEvent(mouseEvent, CfxMouseButtonType.Left, true, 1);
                    isTouch = false;
                }



                // keyboard
                for (int i = 0; i < keyCode.Count; i++)
                {
                    if (!FKeyCodeIn.Contains(keyCode[i]))
                    {
                        CfxKeyEvent keyEvent = new CfxKeyEvent();

                        keyEvent.Type           = CfxKeyEventType.Keyup;
                        keyEvent.WindowsKeyCode = keyCode[i];
                        keyEvent.NativeKeyCode  = keyCode[i];

                        browser.Host.SendKeyEvent(keyEvent);

                        keyCode.RemoveAt(i);
                        i--;
                    }
                }

                if (FKeyCharIn.SliceCount > 0 && FKeyCodeIn.SliceCount > 0)
                {
                    int count = Math.Max(FKeyCharIn.SliceCount, FKeyCodeIn.SliceCount);
                    for (int i = 0; i < count; i++)
                    {
                        int code = FKeyCodeIn[i];
                        if (code >= 0 && FKeyEventTypeIn[i] != KeyNotificationKind.KeyUp && !keyCode.Contains(code))
                        {
                            CfxKeyEvent keyEvent = new CfxKeyEvent();

                            keyEvent.Type           = CfxKeyEventType.Keydown;
                            keyEvent.WindowsKeyCode = code;
                            keyEvent.NativeKeyCode  = code;

                            browser.Host.SendKeyEvent(keyEvent);
                        }

                        short ch = (short)(FKeyCharIn[i].Length > 0 ? FKeyCharIn[i][0] : 0);
                        if (ch > 0)
                        {
                            CfxKeyEvent keyEvent = new CfxKeyEvent();

                            keyEvent.Type                = CfxKeyEventType.Char;
                            keyEvent.Character           = ch;
                            keyEvent.UnmodifiedCharacter = ch;
                            keyEvent.WindowsKeyCode      = ch;
                            keyEvent.NativeKeyCode       = ch;

                            browser.Host.SendKeyEvent(keyEvent);
                        }
                    }
                }


                if (FReloadIn[0])
                {
                    browser.ReloadIgnoreCache();
                }

                if (zoomLevel != browser.Host.ZoomLevel)
                {
                    browser.Host.ZoomLevel = zoomLevel;
                }

                if (FUpdateDomIn[0])
                {
                    browser.MainFrame.GetSource(visitor);
                }

                if (isDocumentReady)
                {
                    if (FBindIn.IsChanged && FBindIn[0] && FMethodIn.SliceCount > 0)
                    {
                        BindFunctions(FObjectIn[0], FMethodIn.ToArray());
                    }

                    if (FScrollToIn.IsChanged)
                    {
                        scroll = FScrollToIn[0];

                        ExecuteJavascript(
                            string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          @"window.scrollTo({0} *  document.body.scrollWidth, {1} * document.body.scrollHeight);",
                                          scroll.x,
                                          scroll.y
                                          )
                            );
                    }
                }

                if (FExecuteIn[0])
                {
                    ExecuteJavascript(FJavaScriptIn[0]);
                }

                if (FEvaluateJavaScriptIn[0])
                {
                    EvaluateJavascript(FJavaScriptIn[0], (value, exception) =>
                    {
                        FResultJSOut[0] = CfrV8ValueToString(value);
                    });
                }
            }


            if (FWidthIn.IsChanged || FHeightIn.IsChanged)
            {
                if (FWidthIn.SliceCount > 0 && FHeightIn.SliceCount > 0 && FWidthIn[0] > 0 && FHeightIn[0] > 0)
                {
                    lock (bLock)
                    {
                        width  = FWidthIn[0];
                        height = FHeightIn[0];

                        image        = new byte[width * height * 4];
                        isImageReady = false;
                    }

                    if (browser != null)
                    {
                        browser.Host.WasResized();
                    }

                    invalidate = true;
                }
            }

            FIsLoadingOut[0] = !isDocumentReady;

            this.Mouse    = FMouseIn[0];
            this.Keyboard = FKeyboardIn[0];

            //CfxRuntime.DoMessageLoopWork();
        }
Beispiel #12
0
 /// <summary>
 /// Send a key event to the browser.
 /// </summary>
 /// <remarks>
 /// See also the original CEF documentation in
 /// <see href="https://bitbucket.org/chromiumfx/chromiumfx/src/tip/cef/include/capi/cef_browser_capi.h">cef/include/capi/cef_browser_capi.h</see>.
 /// </remarks>
 public void SendKeyEvent(CfxKeyEvent @event)
 {
     CfxApi.cfx_browser_host_send_key_event(NativePtr, CfxKeyEvent.Unwrap(@event));
 }