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.

Catch events Enter/Exit for Chromium window

Post Reply
User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

Catch events Enter/Exit for Chromium window

Post by xpert13 »

Hello.

Every Delphi visual component has events OnEnter (component was focused) and OnLeave (focuse was moved to another component). How can I catch such events for Chromium? I have found just OnGotFocus event (but I am not sure that it is exactly I looking for). I can't found some events to catch focus loosing. Can somebody help me?
User avatar
salvadordf
Posts: 4058
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Catch events Enter/Exit for Chromium window

Post by salvadordf »

Hi,

OnGotFocus can be used as OnEnter and it seems to work in the same way.

OnTakeFocus on the other hand is similar to OnExit but not exactly the same.

This is what the code comments say:
/include/capi/cef_focus_handler_capi.h

Code: Select all

  ///
  // Called when the browser component is about to loose focus. For instance, if
  // focus was on the last HTML element and the user pressed the TAB key. |next|
  // will be true (1) if the browser is giving focus to the next component and
  // false (0) if the browser is giving focus to the previous component.
  ///
After a few tests, it's only triggered when you press TAB on the last focusable HTML element but not when the mouse clicks on another component outside the browser.

Possible workarounds :
  • Use the OnEnter, OnExit events on other components.
  • Use the Onactivate, OnDeactivate events on TApplication.
  • Use Javascript events.
User avatar
salvadordf
Posts: 4058
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Catch events Enter/Exit for Chromium window

Post by salvadordf »

If you use a browser in OSR mode then you can use TChromium.SendKeyEvent. Take a look at the SimpleOSRBrowser demo for more details.

If you use a browser in normal mode then you can use normal Windows messages to simulate key presses :
https://stackoverflow.com/questions/163 ... -component
http://delphidabbler.com/tips/170

If you send Windows messages try to send them to TChromium.WindowHandle. If that doesn't work then try to send them to TChromium.RenderHandle.
Post Reply