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?

EDIT: Here's a man page with a small example: ( )

Except theoretically you would probably ( ) 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

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