Link to home
Start Free TrialLog in
Avatar of sendhil_an
sendhil_an

asked on

System.Windows.Forms.SendKeys

hi,
   Iam having a small problem in using the System.Windows.Forms.SendKeys API to send input to an active appication. I have an exe file for adding two numbers. I have to give input to that and get the result. My code ( which i have given below) works sometime and does not work someother time. It gives and unhandled exception error. can anyone tell me why?
 
   Dim myProcess As Process = New Process()
   myProcess.StartInfo.FileName = "Addition.exe"
   myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
   myProcess.EnableRaisingEvents = True
   myProcess.Start()
    Try
         If myProcess.Responding Then
           System.Windows.Forms.SendKeys.SendWait("2")
           System.Windows.Forms.SendKeys.SendWait("{ENTER}")
           System.Windows.Forms.SendKeys.SendWait("3")
           System.Windows.Forms.SendKeys.SendWait("{ENTER}")
           System.Windows.Forms.SendKeys.Send("{ENTER}")
           System.Windows.Forms.SendKeys.Flush()
         Else
            myProcess.Kill()
        End If

-sendhil

ASKER CERTIFIED SOLUTION
Avatar of brother7
brother7
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: brother7 {http:#9624332}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer