Simulating Keyboard Events

I would simulate keyboard events in a c++ program.I would "trick" the computer, so it "think" a key has been pressed.I work in Fedora 14.Anyone know something about that?
May I ask why you would need to do this?
Not sure if this has any real purpose in a program since the user is usually the one responsible for the typing of letters.

As Lumpkin said, can we get more information on what you plan to do with this?
I have to write a program whose purpose is to write the root user password on the terminal automatically.
I don't want make any illegal action, but only this program needs root privileges and I don't want all users to use root user.That's all.
So what does simulating keyboard events have to do with it?

You could grab the root password store it in a string and put it up with
std::cout << root_password;

Or am I lost to what you want?
I have tryed what you have just suggested but it doesen't work.After you write the command "su" on the terminal, then appear on the screen "Password:" and you have to write it manually.I want do that automatically with my c++ program.
So you're looking to pipe the two programs together?

http://en.wikipedia.org/wiki/Pipeline_(Unix)

EDIT: Here's a man page with a small example: ( http://man.yolinux.com/cgi-bin/man2html?cgi_command=pipe(2) )

Except theoretically you would probably ( http://linux.die.net/man/3/exec ) after forking. Or you could just pipe them from the command line like pipingProgam | su
Last edited on
Thank you drew 887 your suggestion have been useful.
when I do
echo password | su -l
I get
su: must be run from a terminal

as output.
while I think the expected output is
Password: 

or
Password: 
su: Authentication failure
Last edited on
Topic archived. No new replies allowed.