Sending keyboard input

This is a discussion on Sending keyboard input within the C Programming forums, part of the General Programming Boards category; Currently I have a program that prompts me to enter information from the keyboard. I want to write a C ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    Question 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.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You could redirect input from stdout of one program to stdin of the other. That would be slightly easier than actually simulating keystrokes.

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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...

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Remember that Windows can't fork() .

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  2. Reading and processing input from keyboard
    By papagaio in forum C Programming
    Replies: 1
    Last Post: 11-12-2008, 02:59 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Intercepting keyboard input
    By EvBladeRunnervE in forum Windows Programming
    Replies: 3
    Last Post: 01-08-2004, 08:03 AM
  5. Need help with Console Keyboard Input
    By pawelx2 in forum Game Programming
    Replies: 5
    Last Post: 05-30-2002, 11:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21