delphichromiumdelphi-xe2virtual-keyboardcef4delphi

DCEF4 virtual keyboard is not showing up


I am using CEF4Delphi from https://github.com/salvadordf/CEF4Delphi I am editing PopupBrowser2 example. There is Chromium1 component. I have added event, that is supposed to notify when keyboard is requested:

procedure TForm1.Chromium1VirtualKeyboardRequested(Sender: TObject; const browser: ICefBrowser;
  input_mode: TCefTextInpuMode);
begin
   caption := 'kbd';
end;

Sadly, when example loads google page, I click on search edit box and event is not called. How can I make event to be called?


Solution

  • TChromium.OnVirtualKeyboardRequested is one of the events of ICefRenderHandler and that handler is only used by browsers in off-screen mode (OSR mode).

    The PopupBrowser2 demo uses browsers in normal mode (a.k.a. "windowed mode") which means that none of the ICefRenderHandler events will be triggered.

    With PopupBrowser2 you will have to use a different event called GlobalCEFApp.OnFocusedNodeChanged

    Check the node.name with the HTML tag names that should show the virtual keyboard like "input" or "textarea" inside GlobalCEFApp.OnFocusedNodeChanged.

    That event is executed in the render process and you will have to send a process message to the main browser process to show the keyboard.

    The DOMVisitor demo shows you how to send that process message with the some parameters if you need them : https://github.com/salvadordf/CEF4Delphi/blob/132edb2e8895d998d3e3810982c95b9f845d78f8/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas#L305

    The browser process will receive that message in the TChromium.OnProcessMessageReceived event as you can see here : https://github.com/salvadordf/CEF4Delphi/blob/132edb2e8895d998d3e3810982c95b9f845d78f8/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas#L432

    Notice that TCefProcessMessageRef is created by the "New" function with a name. When you implement TChromium.OnProcessMessageReceived in your application you'll have to compare that message.name has the same name value before handling it.