Page 1 of 2

SendMouseWheelEvent does not work

Posted: Tue Feb 18, 2020 8:59 am
by micmorozov
Hello!

Sometimes, after clicking on the link to the site, the mouse scroll simulation stops working.

Code: Select all

Chromium1.SendMouseWheelEvent(@event, -100, 0);
Why can this happen?

Thanks

Re: SendMouseWheelEvent does not work

Posted: Tue Feb 18, 2020 9:07 am
by salvadordf
Hi,

Please, provide the steps necessary to reproduce that issue. Preferably using one of the CEF4Delphi demos or the official CEF sample application.

Re: SendMouseWheelEvent does not work

Posted: Wed Feb 19, 2020 3:37 am
by micmorozov
How to repeat a problem?

1. Get SimpleBrowser2 from demos
2. Put TButton on the form
3. Write the next code:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var TempMouseEvent: TCefMouseEvent;
begin
  TempMouseEvent.x         := 100;
  TempMouseEvent.y         := 100;
  TempMouseEvent.modifiers := GetCefMouseModifiers(0);
  DeviceToLogical(TempMouseEvent, GlobalCEFApp.DeviceScaleFactor);
  Chromium1.SendMouseWheelEvent(@TempMouseEvent, 0, -50);
end;
4. Run app
5. Load http://mymoney.su
6. Click the button - Page scrolls
7. Click on menu link on the site.
8. Click the button - Page NOT scrolls. Why? if you spin the wheel of a real mouse, then the scroll will work by the button

Re: SendMouseWheelEvent does not work

Posted: Wed Feb 19, 2020 9:20 am
by salvadordf
This may be a focus issue.

Each time you click on a control the browser loses the focus and that button is simulating a mouse event over a browser without focus.

Besides that, the browser captures the mouse to scroll the whole page or the contents of the element under the mouse pointer. I'm not sure what could happen if the browser gets conflicting information when the user clicks on an element and then receives a mouse event from a point outside that element.

If that CEF function is not 100% reliable I would try this :
  • Use JavaScript functions like window.scrollBy instead of the CEF functions.
  • Send WM_MOUSEWHEEL messages to TChromium.RenderHandle
  • Use a browser in OSR mode to simulate full keyboard and mouse events.

Re: SendMouseWheelEvent does not work

Posted: Wed Feb 19, 2020 10:45 am
by micmorozov
salvadordf wrote: Wed Feb 19, 2020 9:20 am Each time you click on a control the browser loses the focus and that button is simulating a mouse event over a browser without focus.
But the first time the scroll works. Only after clicking on the link stops.
salvadordf wrote: Wed Feb 19, 2020 9:20 am If that CEF function is not 100% reliable I would try this :
Use JavaScript functions like window.scrollBy instead of the CEF functions.
Send WM_MOUSEWHEEL messages to TChromium.RenderHandle
Use a browser in OSR mode to simulate full keyboard and mouse events.
Thanks for the advice. I'll try

Re: SendMouseWheelEvent does not work

Posted: Mon Feb 24, 2020 6:36 am
by micmorozov
OSR mode helped. But the scroll wheel in this mode is not smooth. With what it can be connected?

GlobalCEFApp.SmoothScrolling := STATE_ENABLED;

But it is not helped.

Re: SendMouseWheelEvent does not work

Posted: Mon Feb 24, 2020 8:47 am
by salvadordf
The GlobalCEFApp.SmoothScrolling needs to be set before the GlobalCEFApp.StartMainProcess call in the DPR file.

Build the SimpleOSRBrowser demo with the GlobalCEFApp.SmoothScrolling property and without it. Run them side by side and you'll notice that the scroll is smoother in one of them.

Re: SendMouseWheelEvent does not work

Posted: Mon Feb 24, 2020 10:05 am
by micmorozov
thank you.

I have an OSR browser in the tab. When I close a tab or program, System Error Code 5 appears
Why such an error can pop up?

Re: SendMouseWheelEvent does not work

Posted: Mon Feb 24, 2020 10:20 am
by salvadordf
That error code appears when a control handle has been created and destroyed in different threads.

Don't create, destroy or modify VCL controls inside the CEF events because most of them are executed in CEF threads. Some VCL controls will recreate handles when you try to modify them and this can be problematic if you do it inside CEF events.

The CEF4Delphi demos try to be as simple and easy as possible and they often don't follow that rule.

Re: SendMouseWheelEvent does not work

Posted: Tue Feb 25, 2020 10:02 am
by micmorozov
Have you any real example of CEF4delphi?