Keypress detection with getchar ()

When I run the following program:

int main() { getchar(); return 0; } 

And I press any of the arrow keys, for example ↑ (up arrow) on the console, which I get ^[[A I want to know what that means. In particular, I want to know what ^[ means.

+4
source share
2 answers

^ is the abbreviation for the Ctrl key. Then ^[ is the terminal exit code for ESC , an escape character.

+4
source

The carriage character before the other character is the escape sequence for the control character (one of the characters with code points from 0 to 31). ^ [is an escape character named ESC and usually introduces escape sequences for your terminal. This is what your keyboard sends when you press the up arrow.

+2
source

Source: https://habr.com/ru/post/1501166/


All Articles