0

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!

2
  • Use termios() to turn off the ECHO flag. Commented Aug 10, 2017 at 1:17
  • Thanks @Barmar, that's what I've been looking for. If you write it as an answer, I'll be happy to mark it as the correct one. Also, do you know if it's possible to hide the blinking cursor? Commented Aug 10, 2017 at 1:30

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.