Page 1 of 1

About OSR keyevent

Posted: Thu Apr 25, 2024 2:40 pm
by bobpang
Now i defined a procedure like

Code: Select all

procedure sendCtrlTab(Chromium: TChromium);
var
  TempKeyEvent   : TCefKeyEvent;
begin
  TempKeyEvent.kind                    := KEYEVENT_RAWKEYDOWN;
  TempKeyEvent.modifiers               := EVENTFLAG_SHIFT_DOWN;
  TempKeyEvent.windows_key_code        := 9;
  TempKeyEvent.native_key_code         := 0;
  TempKeyEvent.is_system_key           := ord(False);
  TempKeyEvent.character               := #0;
  TempKeyEvent.unmodified_character    := #0;
  TempKeyEvent.focus_on_editable_field := ord(False);
 
  Chromium.SendKeyEvent(@TempKeyEvent);
  TempKeyEvent.kind := KEYEVENT_KEYUP;
  Chromium.SendKeyEvent(@TempKeyEvent);
end;
if we click a button to trigger the event, it works well

Code: Select all

procedure Tfrom1.Button1Click(Sender: TObject);
begin
  sendCtrlTab(Chromium1);
end;
but Write it in Chromium1Jsdialog and it won't work again,How to correct it?

Code: Select all

procedure TbrowseFrm.Chromium1Jsdialog(Sender: TObject;
  const browser: ICefBrowser; const originUrl: ustring;
  dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring;
  const callback: ICefJsDialogCallback; out suppressMessage, Result: Boolean);
begin
  Result := true;
  sendCtrlTab(Chromium1);
end;

Code: Select all

procedure Tfrom1.Button2Click(Sender: TObject);
begin
  Chromium1.ExecuteJavaScript('alert("send keyevent");','',0);
end;

Re: About OSR keyevent

Posted: Fri Apr 26, 2024 10:10 am
by salvadordf
Try sending a custom message from Chromium1Jsdialog to the main form that calls sendCtrlTab in the main application thread.