Search code examples
cstdoutstdinsystem-callsarrow-keys

How to ignore arrow keys in C reading from stdin?


I'm reading from the standard input using the read() system call but there's a tiny thing that bothers me. I can't use the arrow keys... What I really wanted to do was to use arrow keys to go back and forth within the typed text but I think that's not that easy... So, what I at least want to do, is to ignore them.

Right now, pressing any of the arrow keys produces strange output and I want to prevent anything from being written to the standard output (consequently read from the standard input in my read() system call).

Is this easily possible to achieve or it's not that easy?


Solution

  • In order to interpret the arrow keys the way you would ideally like to (i.e. to move back and forth and edit the input), you generally need to use a library. For Linux, the standard is GNU Readline. Hopefully someone else can say what you would normally use for a Windows CLI app.