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.

Strange behavior of SendKeyEvent

Post Reply
User avatar
RedOctober
Posts: 8
Joined: Sat Jul 07, 2018 12:59 pm
Location: Montenegro
Contact:

Strange behavior of SendKeyEvent

Post by RedOctober »

Hello,

please take a look to a code below:

Code: Select all

var
    key_event: tcefkeyevent;
    str: widestring;
    q: integer;    
begin    
    str:='super.login_myusername';
    
    key_event.focus_on_editable_field := 1;
    key_event.modifiers := GetCefKeyboardModifiers(ord(str[q]), 0000000);
    for q := 1 to length(str) do

    begin
      FillChar(key_event, SizeOf(tcefkeyevent), 0);
      key_event.kind := KEYEVENT_KEYDOWN;
      key_event.character := str[q];
      key_event.windows_key_code := ord(str[q]);
      key_event.native_key_code := 0000000;
      action_browser.browser.Host.SendKeyEvent(@key_event);

      FillChar(key_event, SizeOf(tcefkeyevent), 0);
      key_event.kind := KEYEVENT_CHAR;
      key_event.character := str[q];
      key_event.windows_key_code := ord(str[q]);
      key_event.native_key_code := 0000000;
      action_browser.browser.Host.SendKeyEvent(@key_event);

      FillChar(key_event, SizeOf(tcefkeyevent), 0);
      key_event.kind := KEYEVENT_KEYUP;
      key_event.character := str[q];
      key_event.windows_key_code := ord(str[q]);
      key_event.native_key_code := 0000000;
      action_browser.browser.Host.SendKeyEvent(@key_event);
    end;
end;
In general it works pretty fine, but:
1. Completely ignore a dot char (.) and few more chars like #$%^&*( , but send fine a chars like ! and @, for example.
2. When the char "y" occurs in string, it hangs: I have to click to the field manually, then it continues to send the rest keys after "y".

What am I doing wrong? Thanks in advance for answers!
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Strange behavior of SendKeyEvent

Post by salvadordf »

Hi,

I typed all those characters using the SimpleOSRBrowser demo in google.com and it works fine.

Please, try the SimpleOSRBrowser demo with those characters. If it works in your computer then I would add some code to the AppEventsMessage procedure in that demo to log the complete sequence of messages and all the TCefKeyEvent fields. You can use that log to send the same sequence of messages whenever you like.

There are some differences filling the TCefKeyEvent fields between that code and the AppEventsMessage procedure in SimpleOSRBrowser. key_event.character, key_event.windows_key_code and key_event.native_key_code have different values in the demo.
Post Reply