How to wait for a window to appear before sending keystrok using sendkeys?
-
Hi Experts, I have an application in C# where i am calling a
.reg file
using process class. now i want to send keystrokey
first and then i need to wait for next megssage box to appear then sendenter
to it.System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
SendKeys.Send("{y}"); SendKeys.Send("{ENTER}");
now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the
enter
key stroke. Please Help Regards, Paramhans Dubey. -
Hi Experts, I have an application in C# where i am calling a
.reg file
using process class. now i want to send keystrokey
first and then i need to wait for next megssage box to appear then sendenter
to it.System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
SendKeys.Send("{y}"); SendKeys.Send("{ENTER}");
now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the
enter
key stroke. Please Help Regards, Paramhans Dubey.Why not put a #n seconds delay between the commands. Find out the windows handle of the dialog and poll the windows collect to detect when it is present.
-
Hi Experts, I have an application in C# where i am calling a
.reg file
using process class. now i want to send keystrokey
first and then i need to wait for next megssage box to appear then sendenter
to it.System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
SendKeys.Send("{y}"); SendKeys.Send("{ENTER}");
now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the
enter
key stroke. Please Help Regards, Paramhans Dubey.Hi, the quick and dirty solution is by inserting a sufficiently large delay (Thread.Sleep). the higher performance solution I typically use needs some P/Invoke to Win32 functions such as GetForegroundWindow and GetWindowText, all in a polling retry-and-sleep loop. :)
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
-
Hi, the quick and dirty solution is by inserting a sufficiently large delay (Thread.Sleep). the higher performance solution I typically use needs some P/Invoke to Win32 functions such as GetForegroundWindow and GetWindowText, all in a polling retry-and-sleep loop. :)
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
By Replacing
System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
with
System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());
solved my problem.
/S
is used for merger in silent mode. -
By Replacing
System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
with
System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());
solved my problem.
/S
is used for merger in silent mode.Thanx anyways guys for your replies.
-
By Replacing
System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");
with
System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());
solved my problem.
/S
is used for merger in silent mode.Hi, I have two comments: 1. What you say does not achieve "i want to send keystroke y first and then i need to wait" at all. Make sure you ask the right question in future. 2. There is a shorthand for
'"'.ToString()
, it is"\""
and you can even merge it with a previous string literal. :)Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!