Page 1 of 1

How to simulate ctrl+a

Posted: Wed Oct 02, 2019 12:11 pm
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!

Re: How to simulate ctrl+a

Posted: Wed Oct 02, 2019 4:37 pm
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

Re: How to simulate ctrl+a

Posted: Thu Oct 03, 2019 5:13 am
by ForestListener
Thank you, Salvador.

Excuse me, where is this demo, can you share the link?

Re: How to simulate ctrl+a

Posted: Thu Oct 03, 2019 7:22 am
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.

Re: How to simulate ctrl+a

Posted: Thu Oct 03, 2019 9:44 am
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?

Re: How to simulate ctrl+a

Posted: Thu Oct 03, 2019 10:17 am
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.

Re: How to simulate ctrl+a

Posted: Thu Oct 03, 2019 11:08 am
by ForestListener
Thank you!