4

When I run the following program:

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

And I press any of the arrow keys like (up arrow) on the console I get ^[[A. I want to know what this means. Specifically, I want to know what ^[ means.

johnchen902
  • 9,531
  • 1
  • 27
  • 69
Alex_ban
  • 221
  • 2
  • 11

2 Answers2

4

The ^ is a shorthand notation for Ctrl key. Then ^[ is a terminal escape code for ESC, the escape character.

Mihai Maruseac
  • 20,967
  • 7
  • 57
  • 109
2

A caret character in front of another character is an escape sequence for a control character (one of the characters with code points 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 hit the up arrow.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • But why does the keyboartd sends that is it a part of the scan code? – Alex_ban Sep 08 '13 at 14:47
  • There is no ASCII code for the upwards arrow. There is an ANSI standard that describes what escape sequences keys are being converted into that do not have an ASCII code associated. This also specifies that ↑ is mapped to ^[[A. – fuz Sep 08 '13 at 15:31