0

I am trying to write a C program that uses Linux system calls to emulate the behaviour of the more command in the Linux terminal. Since the users might enter commands such as q to finish the execution, I am trying to find a way in which to read keystrokes from the standard inout without using read(...), as I don't want the pressed key to appear on the standard output.

In other words, I want to be able to detect pressed keys without them being written.

I have read that ioctl() and the termios struct can somehow be used for this purpose, but I am not sure how they are used (I find the man pages somewhat cryptic).

I have found a few answers to the use of those functions, but all of them seem too complicated. There must be an easier way to detect simple keystrokes, isn't there?

Noel Arteche
  • 201
  • 1
  • 3
  • 1
    You could probably just use [`ncurses`](https://www.gnu.org/software/ncurses/). Or look at the source code for `more` (or `less`) and see how they handle user input ? – Paul R Mar 09 '18 at 09:27

1 Answers1

2

man 3 termios, tcsetattr, disable ECHO on stdin.

For a longer explanation see: Hide password input on terminal

Alternatively, you could go through below termios abstraction, use input layer, /dev/input/*, but I think you'll need to disable forwarding events from your input devices to upper layers then.

domen
  • 1,819
  • 12
  • 19