Using C# how do I send keystrokes to an application

I have launched an app via System.Diagnostics.Process.Start.
How do I send keystrokes to that app (In VB6 I would have used SendKeys).
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
After you start the Process, use WaitForInputIdle() to make sure it is ready to receive input...

   Process p = Process.Start(@"c:\someFile.exe");

Does that help?
BinuthConnect With a Mentor Commented:
use SendKeys.Send() method

kev1970Author Commented:
Thanks. How do I send the arrow keys?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

kev1970Author Commented:
I'm trying to:
Launch the app
Move to the 4th row of the listbox
Press enter

So far I have launched the app sucessfully but SendKeys.SendWait("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}"); does not do anything.
How do I ensure that the app has the focus when I send the keystrokes?
I think the listbox is not active when you are sending the arrow key.......

In case of manual operation, you will select the listbox ( whcih makes it focused ) and you use arrows to move have to produce the same sequence.....whats missing is making listbox focused...

I think you need to set the tab stop for the list box and use tab keys to make listbox focused and then use arrow keys........
Anurag ThakurConnect With a Mentor Technical ManagerCommented:
the following links might provide some useful insite to solve the problem
VB Sample
kev1970Author Commented:
Normally, I double-click the app then use the arrow keys then hit the enter key. In other words, the listbox has focus as soon as the app starts.
How do I ensure that the app has the focus when I send the keystrokes?
kev1970Author Commented:
Sorry for the delay.
I also used the following code to focus the (called) app.:

bool ret = SetWindowPos((int)p.Handle, HWND_TOPMOST, 0, 0, 0, 0, (uint)(SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
kev1970Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.