Windows Develop Bookmark and Share   
 index > Windows Forms General > SendKeys timing issue
 

SendKeys timing issue

Hi all,

I have some code that is sending keys to some input file boxes (this is a work around since you cannot change file input values) (WebBrowser control by the way).... all is well except sendkeys cannot keep up with the next command to click the submit button...

My question is , how do i slow down the next step so sendkeys can catch up... I have tried a timer with no success!!

here is what i have... ( // tabbing through to get to the file inputs)

for (int a =0; a<6; a++)

{

SendKeys.Send("{tab}");

}

SendKeys.Send(imagebox1.Text);

for (int a = 0; a < 2; a++)

{

SendKeys.Send("{tab}");

}

SendKeys.Send(imagebox2.Text);

for (int a = 0; a < 2; a++)

{

SendKeys.Send("{tab}");

}

SendKeys.Send(imagebox3.Text);

for (int a = 0; a < 2; a++)

{

SendKeys.Send("{tab}");

}

SendKeys.Send(imagebox4.Text);

// right here is where my problem is .. if i comment out chkElem.InvokeMember("click") then send keys is ok and the file inputs populate.. otherwise it submits the form without catching up..

HtmlElement chkElem = doc.GetElementById("submit");

chkElem.Focus();

chkElem.InvokeMember("click");

dn8  Thursday, July 19, 2007 6:09 AM
MessageBox will throw a monkey wrench in the works. Not sure what happens if you try to wait on yourself. Guess it doesn't work well. Try starting a timer after the SendKeys calls, a second or so, then do the submit in the Tick event.
nobugz  Thursday, July 19, 2007 6:38 PM
Yes, you're going to have to wait to let the WebBrowser catch up with the keystrokes you send it. SendKeys.SendWait() is the best way, Application.DoEvents() a distant second.
nobugz  Thursday, July 19, 2007 4:08 PM

I must be missing something because it is still not waiting...

Even using this simple code, I get my message box before the field populates .. I press ok at the prompt and then it populates the field with "Hello"

SendKeys.Send("{tab}"); // tabs to my field

SendKeys.SendWait("Hello"); // does not wait!

MessageBox.Show("done"); //prompts message box, I hit ok, then it populates my field ??

Am I missing something? A namespace maybe?

thanks...

dn8  Thursday, July 19, 2007 6:26 PM
MessageBox will throw a monkey wrench in the works. Not sure what happens if you try to wait on yourself. Guess it doesn't work well. Try starting a timer after the SendKeys calls, a second or so, then do the submit in the Tick event.
nobugz  Thursday, July 19, 2007 6:38 PM

Bingo!! that worked with the timer!

Hrmmm I tried that last night with no avail! Of course I changed a bunch of code today, that was probably messing it up...

thanks nobugz

dn8  Thursday, July 19, 2007 7:02 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom control for time editing
• Hiding tab buttons on tab controls
• i need sample code in c# for shellexecute
• remove radiobuttonlist listitem
• Concurrent changes in UserControls and Application close event handling
• Need to change the System Date Format through ASP
• Windows Application to Web Application
• text change question
• BringToFront & SendToBack in an Editor for controls.
• Problem - VB.Net 2005 - update data in to Ms access