-
Sending keyboard input
Currently I have a program that prompts me to enter information from the keyboard. I want to write a C program that launches this program and automatically enters the correct information. I'm not sure how to send keyboard input from one program to another. How can I go about doing this? I'm running Windows XP. Thanks for any help.
-
You could redirect input from stdout of one program to stdin of the other. That would be slightly easier than actually simulating keystrokes.
-
This is very dependant on your OS, and unfrotunately, I've only ever done this on Linux. But it always helps to find documentation when you know the correct terms. So here they are:
Your first programs spawns a new process (forks), and creates a pipe (a file that one process can write to and the other can read). In the new process, you assign this new pipe to stdin, and if you want you can assign stdout to some other file or something. Then you execute your program from within that process. In the parent process, you just send you data into that pipe, and it will appear to your other program as if it was receiving those key strokes.
So you'll want to learn about "handling processes", and "interprocess communication" on windows. Hopefully that's enough to point in the right direction quickly...
-
Remember that Windows can't fork() :D.
-