title: Ncurses: F1-F5 keys
body: <p>I have a Probclem with functions keys in curses.h.
  I have this littel programm seen on different websites/tutorials</p>
  
  <pre><code>#include &lt;ncurses.h&gt;
  
  int main()
  {       int ch;
  
      initscr();                      /* Start curses mode            */
      raw();                          /* Line buffering disabled      */
      keypad(stdscr, TRUE);           /* We get F1, F2 etc..          */
      noecho();                       /* Don't echo() while we do getch */
  
      printw("Type any character to see it in bold\n");
      ch = getch();
      while (ch != KEY_F(1))
      {
              if(ch == KEY_F(1))      
                      printw("F1 Key pressed: Ending program.\n");
  
              else
              {       printw("The pressed key is ");
                      attron(A_BOLD);
                      printw("%c\n", ch);
                      attroff(A_BOLD);
              }
  
              refresh();     
  
              ch = getch();
  
      }
      printw("end\n");
      endwin();                       /* End curses mode                */
  
      return 0;
  }
  </code></pre>
  
  <p>The keys F6-F12 works fine and the code which is returned is also fine (for example: 270 if F6 ist pressed). But if I press F5 not 269 is returned, like it would be supposed to be, instead the following is happening (only by pressing F5 once):</p>
  
  <pre><code>Type any character to see it in bold
  The pressed key is ^[
  27
  The pressed key is [
  91
  The pressed key is 1
  49
  The pressed key is 5
  53
  The pressed key is ~
  126
  </code></pre>
  
  <p>So I think the whole Escape Sequence ist returned. I read on the internet about this problem and two times there was a hint which describes to change the TERM variable to xterm or vt100. So I tried to change TERM to vt 220 and also xterm, but nothing change. When i changed it to vt100 also F6-F12 didn't work.</p>
  
  <p>Can anybody help me how I can recognize if the user presses F1-F5? Keys like enter, Backspace, up, down, etc. are recognized fine.</p>
  
  <p>best regards</p>