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.

Check "mouse clicked" event inside Chromium browser.

Post Reply
michal@dorfin.waw.pl
Posts: 41
Joined: Sun Feb 05, 2017 8:53 am

Check "mouse clicked" event inside Chromium browser.

Post by michal@dorfin.waw.pl »

Is there any way to check if user clicked on the webpage in Chromium browser ?
I don't need the coordinates. I just need to know if user is active.
Is there any "event" on TChromium that I could handle ?

I know that I can check mouse events in Javascript and send message from renderer process to main process and execute my code in Delphi.
But I'd like to avoid injecting any JS code in the page.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Check "mouse clicked" event inside Chromium browser.

Post by salvadordf »

Hi,

Use the TChromium.OnRenderCompMsg event and add this code to intercept the Windows message for mouse clicks :

Code: Select all

  case aMessage.Msg of
    WM_LBUTTONDOWN :
      begin
        // Your code.
      end;
  end;
michal@dorfin.waw.pl
Posts: 41
Joined: Sun Feb 05, 2017 8:53 am

Re: Check "mouse clicked" event inside Chromium browser.

Post by michal@dorfin.waw.pl »

As usual - quick and perfect answer. THANK YOU!
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Check "mouse clicked" event inside Chromium browser.

Post by salvadordf »

Thanks to you for supporting this open source project in Patreon! :D
Lis97
Posts: 2
Joined: Thu Sep 12, 2024 4:55 pm

Re: Check "mouse clicked" event inside Chromium browser.

Post by Lis97 »

Good day, I have a similar task, I need to take into account the user's activity.
Therefore, there is no need to create a new topic and I am writing in a similar topic.
The task is simple, when you click the left mouse button in the browser, the OnClick() event should be called in the main form.
In the first version of the code, OnClick() works stably in the main form, but clicking the mouse in the browser does not work, it does not follow the links.
In the second case, OnClick() does not work in the main form, but it works fine, clicking the mouse in the browser works fine.
Please tell me what I am doing wrong.

Code: Select all

  case aMessage.Msg of
    WM_LBUTTONDOWN :
      begin
       aHandled := True;
       PostMessage(Handle, WM_LBUTTONDOWN, 0, 0);
      end;
  end;

Code: Select all

  case aMessage.Msg of
    WM_LBUTTONDOWN :
      begin
       PostMessage(Handle, WM_LBUTTONDOWN, 0, 0);
      end;
  end;
Lis97
Posts: 2
Joined: Thu Sep 12, 2024 4:55 pm

Re: Check "mouse clicked" event inside Chromium browser.

Post by Lis97 »

I did it like this, it works :) maybe it will be useful to someone :roll:

Code: Select all

  case aMessage.Msg of
    WM_LBUTTONDOWN :
      begin
       PostMessage(Handle, WM_LBUTTONDOWN, 0, 0);
       PostMessage(Handle, WM_LBUTTONUP, 0, 0);
      end;
  end;
Post Reply