Link to home
Start Free TrialLog in
Avatar of THANASIS FARANTOS
THANASIS FARANTOS

asked on

sending data to dialog box with sendkeys

I want to hadlle a dialog box in order to automatically download a file from a web page (using delphi and Twebbrowser).
So I wrote a code like this ...

procedure WebBrowserDownloadComplete(Sender: TObject);
begin
       SimulateKeystroke(VK_LEFT, 0);
       SimulateKeystroke(VK_RETURN, 0);
end;

Open in new window


First line seems to work (focus moves from cancel button to save button) , but the second line doesn't (save button is not triggered).
Strangely, if i write...

procedure WebBrowserDownloadComplete(Sender: TObject);
begin
       SimulateKeystroke(VK_RETURN, 0);
end;

Open in new window


SimulateKeystroke(VK_RETURN, 0) seems to work, (dialog box is closed, so cancel button is triggered)

I tried some tricks like using SimulateKeystroke(VK_RETURN, 0) repetetively in a loop, or insert delay in the code, but without result.
How can I fix this?
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

I wouldn't go with sending keystrokes. I would read contents of webpage using html dom interface and call appropriate js code.
Here are few articles to help you out:
calling JS functions
Delphi and WBrowser
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.