Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

SendMouseWheelEvent does not work

micmorozov
Posts: 18
Joined: Mon Oct 07, 2019 7:53 am

SendMouseWheelEvent does not work

Post 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
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SendMouseWheelEvent does not work

Post 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.
micmorozov
Posts: 18
Joined: Mon Oct 07, 2019 7:53 am

Re: SendMouseWheelEvent does not work

Post 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
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SendMouseWheelEvent does not work

Post 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.
micmorozov
Posts: 18
Joined: Mon Oct 07, 2019 7:53 am

Re: SendMouseWheelEvent does not work

Post 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
micmorozov
Posts: 18
Joined: Mon Oct 07, 2019 7:53 am

Re: SendMouseWheelEvent does not work

Post 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.
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SendMouseWheelEvent does not work

Post 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.
micmorozov
Posts: 18
Joined: Mon Oct 07, 2019 7:53 am

Re: SendMouseWheelEvent does not work

Post 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?
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SendMouseWheelEvent does not work

Post 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.
micmorozov
Posts: 18
Joined: Mon Oct 07, 2019 7:53 am

Re: SendMouseWheelEvent does not work

Post by micmorozov »

Have you any real example of CEF4delphi?
Post Reply