good evening, I am doing a mouse click simulation + a keyboard simulation, but the form just closes, not immediately, but after some time, what could be the reason?
MouseEvent.x :=30;
MouseEvent.y := 40;
form1.Chromium1.Browser.Host.SendFocusEvent (true);
form1.Chromium1.Browser.Host.SendMouseClickEvent (PCefMouseEvent(@MouseEvent), MBT_LEFT, false, 1);
form1.Chromium1.Browser.Host.SendMouseClickEvent (PCefMouseEvent (@MouseEvent), MBT_LEFT, true, 1);
for I := 0 to length(tel) do
begin
FillChar(event, SizeOf(TCefKeyEvent), 0);
event.kind := KEYEVENT_KEYDOWN;
event.character := tel;
event.windows_key_code :=ord(tel);
form1.Chromium1.Browser.Host.Browser.MainFrame.Browser.Host.SendKeyEvent(@event);
sleep(50);
FillChar(event, SizeOf(TCefKeyEvent), 0);
event.kind := KEYEVENT_CHAR;
event.character := tel;
event.windows_key_code := ord(tel);
form1.Chromium1.Browser.Host.Browser.MainFrame.Browser.Host.SendKeyEvent(@event);
sleep(50);
FillChar(event, SizeOf(TCefKeyEvent), 0);
event.kind := KEYEVENT_KEYUP;
event.character := tel;
event.windows_key_code := ord(tel);
form1.Chromium1.Browser.Host.Browser.MainFrame.Browser.Host.SendKeyEvent(@event);
end;
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.
Closes form
- salvadordf
- Posts: 4565
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Closes form
Maybe there's an AV caused by some access to a nil object or reading memory outside the limits of the memory assigned to a variable.
It's recommended to use the TChromium procedures and functions whenever you can. For example, replace this :
with this :
The calls to SendMouseClickEvent and SendKeyEvent can also be replaced by the TChromium functions.
I assume "tel" is a string but the for..to loop with those initial and final values could cause problems if you try to access a character in that position.
I would also split that function into smaller functions to remove all the "sleep" calls.
It's recommended to use the TChromium procedures and functions whenever you can. For example, replace this :
Code: Select all
form1.Chromium1.Browser.Host.SendFocusEvent(true);
Code: Select all
form1.Chromium1.SendFocusEvent(true);
I assume "tel" is a string but the for..to loop with those initial and final values could cause problems if you try to access a character in that position.
I would also split that function into smaller functions to remove all the "sleep" calls.