There are a lot of examples of how to track keystrokes on C, under Windows, including arrows. Specified getchar() , getch() and library (borlond) conio.h .

I'm interested in sample code in C ++ and under Linux, in the console. So that in the console, when I clicked the arrows, I needed the actions.

Unfortunately, I did not find any examples. :(

ASCII codes know. What function or how to read a character from the keyboard?

It is desirable that without additional pressing Enter after pressing a key. I pressed the letter or the arrow - the right action happened right away.

    2 answers 2

    On the issue, I feel that later, colored symbols will also be needed, and some additional things (cursor positioning). Therefore, I recommend immediately using the ncurses library.

    Googling a bit, found a good tutorial . Literally on the second page is described how to read keystrokes.

    • Thanks, I will study. Colored symbols can be made with console codes. For example, cout << "\ E [01; 31m" << "Red text" << "\ E [01; 0m"; - Infum
    • Yes, it is possible. But some terminals do not support color - you need to do checks. Some terminals support only 16 colors. And ncurses already has many handy features. By the way, a classic example, which is made on ncurses - mc. - KoVadim
    • Your examples use C (gcc) and getch (). I already have working examples on C. But I want to solve the problem in C ++. - Infum
    • @Infum Nobody bothers to use the same code in c ++. He will work. If you wish, you can write a wrapper with classes and poetess. If you want to decide on pure C ++, this is impossible, you still have to use the terminal features and eventually write your library. - KoVadim

    @Infum , if " how it really is arranged " is interesting, then to understand the basics of working with the terminal, start by reading the man termios .

    You can also type in google

     unix Terminal I/O 

    and read, for example, here

    -

    By the way, in the section you are interested in, the differences between C and C ++ are minimal (at the level of the compiler quibbles).

    I do not think that to produce a bunch of classes is a fruitful idea for solving practical problems in this field.