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.

About OSR keyevent

Post Reply
bobpang
Posts: 12
Joined: Fri Feb 14, 2020 2:38 pm

About OSR keyevent

Post 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;
User avatar
salvadordf
Posts: 4074
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: About OSR keyevent

Post by salvadordf »

Try sending a custom message from Chromium1Jsdialog to the main form that calls sendCtrlTab in the main application thread.
Post Reply