Thread: Emulating keystrokes

  1. #1
    Registered User
    Join Date
    Apr 2006

    Emulating keystrokes

    Hi all,

    I have a program running on my gentoo system that controls a USB servosystem, however, it is a command line program that requires user input. I wish to use this program in the start up script of the computer so I was thinking there might be a way to emulate keystrokes to that program to fake a user input to the program and then exit. For example, to turn on the servosystem, you have to type (bold face represents user input)

    gentoo-machine root# ./aducmd 0
    Enter Command <pipe> <w|r|s> [Command] 1 w sk0
    Enter Command <pipe> <w|r|s> [Command] <Enter>
    gentoo-machine root#

    I thought of calling the program like this: echo -e "1 w sk0 \n \n" | ./aducmd 0 but that did not work, does any body know how to make a script or a command to fake user input? (or how to create one?)


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    EXPECT(1)                                                            EXPECT(1)
           expect - programmed dialogue with interactive programs, Version 5
           expect [ -dDinN ] [ -c cmds ] [ [ -[f|b] ] cmdfile ] [ args ]
           Expect  is  a  program  that "talks" to other interactive programs according to a script.
    Read the rest by typing
    man expect
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fake keystrokes to another process
    By Nota in forum Windows Programming
    Replies: 20
    Last Post: 01-26-2009, 11:56 PM
  2. Sending keystrokes to another view
    By azeemanwer in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2007, 10:41 AM
  3. Send keystrokes to a running program via batch file
    By ganjamon in forum Windows Programming
    Replies: 2
    Last Post: 08-16-2005, 08:08 AM
  4. Tracking number of keystrokes
    By thecow in forum Windows Programming
    Replies: 4
    Last Post: 06-04-2003, 03:23 PM