Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send keys to an app not in focus

Status
Not open for further replies.

JunglesMcBeef

Programmer
Sep 18, 2003
266
G'day,

I'm trying to create a console program that opens IE and sends keys to log in. I have already got it working so the browser opens and can be sent keys while in focus, but I don't want the browser to be in focus when I send the keys. Is there a way to do this?

Also, is there some sort of way to determine whether the current site has loaded completely? I have just used System.Threading.Thread.Sleep to allow some time before execution continues to allow the site to load, but this is not efficient and means if a dial-up connection is used (or there is spyware/adware/viruses taking up bandwidth) that the console will have to wait longer.
 
Sendkeys needs the receiver to be in focus (AppActivated). Or use other Windows tools such as the SendMessage Function.

Sendkeys does not know where the receiver is ready to accept -- you'll not get any status messages. SendMessage will wait for the message to be processed by the receiver.
 
You can use a httpwebrequest to post data to a web page so you could do that and have an embedded web browser on your form to show the results.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Ok, but how do I tell whether the page has loaded completely? I don't want to show any results because i'm just logging onto a site and opening another page from it. I can't open the other page until the link has appeared on the page (which only occurs once the page has loaded).
 
I believe the HTTP request will return only after the page has loaded, unless you set a timeout limit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top