[try Beta version]
Not logged in

 
 
Simulating Keyboard Events

Sep 14, 2013 at 4:24pm
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?
Sep 14, 2013 at 6:54pm
closed account (N36fSL3A)
May I ask why you would need to do this?
Sep 15, 2013 at 5:53am
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?
Sep 15, 2013 at 11:28am
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.
Sep 16, 2013 at 11:02am
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?
Sep 16, 2013 at 11:26am
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.
Sep 16, 2013 at 5:52pm
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 Sep 16, 2013 at 5:57pm
Sep 17, 2013 at 6:58pm
Thank you drew 887 your suggestion have been useful.
Sep 23, 2013 at 11:35pm
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 Sep 23, 2013 at 11:38pm
Topic archived. No new replies allowed.