Page 1 of 1

Catch events Enter/Exit for Chromium window

Posted: Tue Aug 15, 2017 6:49 pm
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?

Re: Catch events Enter/Exit for Chromium window

Posted: Wed Aug 16, 2017 10:49 am
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.

Re: Catch events Enter/Exit for Chromium window

Posted: Sat Apr 27, 2019 10:29 am
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.