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.

How to simulate ctrl+a

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

How to simulate ctrl+a

Post by ForestListener »

Hello!

Here is the code to simulate ctrl key press:

Code: Select all

      TempKeyEvent.kind                    := KEYEVENT_RAWKEYDOWN;
      TempKeyEvent.modifiers               := 0;
      TempKeyEvent.windows_key_code        := 17;
      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);
      Chromium1.SendKeyEvent(@TempKeyEvent);

      // WM_CHAR
      TempKeyEvent.kind := KEYEVENT_CHAR;
      Chromium1.SendKeyEvent(@TempKeyEvent);

      // WM_KEYUP
      TempKeyEvent.kind := KEYEVENT_KEYUP;
      Chromium1.SendKeyEvent(@TempKeyEvent);
Please, show the example, how to simulate ctrl+a?

Thank you!
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to simulate ctrl+a

Post by salvadordf »

You can simulate all the key presses but you need the right values for TempKeyEvent.

Open the SimpleOSRBrowser demo, build it and log all the information about key presses that passes through the TForm1.AppEventsMessage procedure.

Read this message for more information :
https://www.briskbard.com/forum/viewtop ... 4231#p4231
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: How to simulate ctrl+a

Post by ForestListener »

Thank you, Salvador.

Excuse me, where is this demo, can you share the link?
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to simulate ctrl+a

Post by salvadordf »

Download the latest CEF4Delphi version in the "master" branch from GitHub :
https://github.com/salvadordf/CEF4Delphi

Decompress it and open the "demos" directory. Then open the "Delphi_VCL" directory or the "Lazarus" directory depending on the IDE you use. The SimpleOSRBrowser demo is in those directories.
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: How to simulate ctrl+a

Post by ForestListener »

Thanks a lot.

It works, but there is the problem

Code: Select all

// WM_KEYDOWN
      TempKeyEvent.kind                    := KEYEVENT_RAWKEYDOWN;
      TempKeyEvent.modifiers               := EVENTFLAG_CONTROL_DOWN;
      TempKeyEvent.windows_key_code        := 65;
      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);
      Chromium1.SendKeyEvent(@TempKeyEvent);

      // WM_CHAR
      TempKeyEvent.kind := KEYEVENT_CHAR;
      Chromium1.SendKeyEvent(@TempKeyEvent);

      // WM_KEYUP
      TempKeyEvent.kind := KEYEVENT_KEYUP;
      Chromium1.SendKeyEvent(@TempKeyEvent);
I've put this EVENTFLAG_CONTROL_DOWN in to TempKeyEvent.modifiers to simulate ctrl+a key combination (select all). It works great when text field contains a letter. But when text field is empty, this code typing letter A instead of simulating ctrl+a.

Can you suggest the solution?
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to simulate ctrl+a

Post by salvadordf »

TempKeyEvent should have different values for WM_KEYDOWN, WM_CHAR and WM_KEYUP.

The message parameters have different meanings in each message :
https://docs.microsoft.com/en-us/window ... wm-keydown
https://docs.microsoft.com/en-us/window ... ev/wm-char
https://docs.microsoft.com/en-us/window ... v/wm-keyup

Log all TempKeyEvent values for each message and repeat all of them in your simulation.
ForestListener
Posts: 44
Joined: Sun Jul 07, 2019 1:46 pm

Re: How to simulate ctrl+a

Post by ForestListener »

Thank you!
Post Reply