2

I have a new problem I came across: I want to create a shell for Linux, but I don't know, how to read special input keys like arrow key, CTRL-key or F11 key, without using ncurses.

I can't use ncurses, since I want to print the STDOUT and STDERR. (Unless there is a way, I don't know of). On the other hand, I don't want to have the "^[[C"-Output. So I probably can't use getchar as well.

So how would I manage to do this?

Poehli
  • 307
  • 4
  • 16
  • 3
    If you don't need too much control over what the arrow keys do, and just want a normal interactive prompt interface, use the [readline](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) or [editline](http://thrysoee.dk/editline/) or [linenoise](https://github.com/antirez/linenoise) library. Another option would be to make your own ncurses-like wrapper around [terminfo/termcap](http://tldp.org/HOWTO/Text-Terminal-HOWTO-16.html). – Adrian Dec 21 '14 at 17:33
  • 1
    possible duplicate of [Recognizing arrow keys with stdin](http://stackoverflow.com/questions/4130048/recognizing-arrow-keys-with-stdin) – David C. Rankin Dec 21 '14 at 17:35
  • thanks to linenoise I got, that it's possible to run a rawmode using `tcgetattr` and `tcsetattr`. More infos are in the [man page](http://linux.die.net/man/3/tcsetattr) for those who care. I can't use any library like that, since it is a homework for my university ;) – Poehli Dec 23 '14 at 20:26
  • possible duplicate of https://stackoverflow.com/questions/34824604/how-do-you-read-the-arrow-keys?r=SearchResults&s=25|70.2442 – luser droog Nov 29 '20 at 03:11

0 Answers0