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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Simulating keypress without OSR mode

Post Reply
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Simulating keypress without OSR mode

Post by ForestListener »

Hello!

Is it possible to simulate keypress? For example, arrow down without OSR mode (i cant use OSR mode by some reason).

I know how to set focus to element on WEBpage by Javascript (i did it).

Now i need to sumulate keypress (like i press keyboard key).

Thank you!
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: Simulating keypress without OSR mode

Post by ForestListener »

Also i've got Access violation any time i modifying Event14: PCEFKeyEvent. Why?

Code: Select all

...
var
...
Event14: PCEFKeyEvent;
begin
FillChar(Event14, SizeOf(PCefKeyEvent), 0);
Event14.kind := KEYEVENT_KEYDOWN; // ACCESS VIOLATION HERE!
//Event14.character:='a'; // ACCESS VIOLATION HERE!
//Event14.windows_key_code:=ord('a'); // ACCESS VIOLATION HERE!
Chromium1.Browser.Host.SendKeyEvent(Event14);
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Simulating keypress without OSR mode

Post by salvadordf »

Hi,

Sorry for the delay.

Please, download the latest CEF4Delphi version from GitHub and run the MiniBrowser demo. It has a new menu option to simulate key presses in normal mode that you can copy and adapt to your application.

https://github.com/salvadordf/CEF4Delph ... r.pas#L851
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: Simulating keypress without OSR mode

Post by ForestListener »

Thank you, Salvador!
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: Simulating keypress without OSR mode

Post by ForestListener »

It is perfectly works!
gresaggr
Posts: 22
Joined: Mon Mar 04, 2019 12:41 pm

Re: Simulating keypress without OSR mode

Post by gresaggr »

Hello.
I can't send characters like this: "!@#$%^&* "with this code.
Could you help me with this problem?
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Simulating keypress without OSR mode

Post by salvadordf »

Hi,

The code in the MiniBrowser demo only simulates WM_KEYDOWN, WM_CHAR and WM_KEYUP messages by calling TChromium.SendKeyEvent with a TCefKeyEvent parameter but some keys might need to simulate additional windows messages with different values for the TCefKeyEvent parameter.

All that information can be obtained with the SimpleOSRBrowser demo. Build it and log all the keyboard related messages that pass through the TForm1.AppEventsMessage procedure when you press those keys.
gresaggr
Posts: 22
Joined: Mon Mar 04, 2019 12:41 pm

Re: Simulating keypress without OSR mode

Post by gresaggr »

salvadordf wrote: Mon Sep 23, 2019 7:38 am All that information can be obtained with the SimpleOSRBrowser demo.
Thank you! It's work!
Post Reply