travisjayday
travisjayday

Reputation: 814

Stopping Linux console from echoing input during program execution

I'm writing a C program that requires to hide the characters a user types from the screen during the program execution. For example, when running the following loop

while (1)
{ 
    //do some work
}

the console displays the blinking cursor (that's good). BUT, when the user types keys on the keyboard, these keys are being echoed out to the console. To visualize it better:

Step 1: Starting the program

root@debian:/home/root# ./program
_

Step 2: User types some characters (even though he shouldn't)

root@debian:/home/root# ./program
AdajfsaSJ_

The characters get echoed on the console. How can I stop this? I know it's theoretically possible, but I can't find out how to implement it.


If you need a better example for what I want to achieve, use the screen command on an empty serial port. screen /dev/tty30 for example. This empties the console and runs the program, HOWEVER, the user is not able to enter any characters (there's a blinking white cursor block and no keyboard characters are being echoed to the console). That's what I need.

Any insight would help, thanks!

Upvotes: 0

Views: 878

Answers (1)

Barmar
Barmar

Reputation: 780724

Use termios() to turn off the ECHO flag of the terminal.

To turn off the text cursor, use the termcap library to control the cursor visibility.

Upvotes: 1

Related Questions