0
votes

I'm testing an ncurses program that was running under ncurses5 but recently compiled under curses6 in a new environment (putty/xterm/virtualbox) and can't get it to recognize any function keys. The arrow keys work fine but only those that use an escape sequence appear to fail.

chtype c;
initscr();
start_color();
noecho();
cbreak();
intrflush(stdscr, TRUE);
keypad(stdscr, TRUE);
c=getch();
printf("c=%d\n", (int)c);

Pressing F1 returns "c=27". I'm using putty and tried various settings with TERM set to xterm. Outside of curses, F1 returns \EOP as expected, and I'm using TERM=xterm which appears to define the function key properly in termcap. I understand the keypad() routine is suppose to cause the getch/wgetch routines to return the numeric key equivalent of 265 KEY_F(1), but I can't get anything but 27 with various combos of break, raw, notimeout, etc.

2

2 Answers

1
votes

Both putty and xterm have several options for their function-keys. The default configurations for each differ, which you can see using

infocmp putty xterm

and it seems that kf1 (F1) is one of many differences, e.g., (putty on the left, xterm on the right):

    kent: NULL, '\EOM'.
    kf1: '\E[11~', '\EOP'.
    kf13: '\E[25~', '\E[1;2P'.
    kf14: '\E[26~', '\E[1;2Q'.
    kf15: '\E[28~', '\E[1;2R'.
    kf16: '\E[29~', '\E[1;2S'.
    kf17: '\E[31~', '\E[15;2~'.
    kf18: '\E[32~', '\E[17;2~'.
    kf19: '\E[33~', '\E[18;2~'.
    kf2: '\E[12~', '\EOQ'.
    kf20: '\E[34~', '\E[19;2~'.
    kf21: NULL, '\E[20;2~'.
    kf22: NULL, '\E[21;2~'.
    kf23: NULL, '\E[23;2~'.
    kf24: NULL, '\E[24;2~'.

(Some copies of ncurses' terminal database are minimal, but there's a full database which includes the putty description).

If the terminal database doesn't show the key as you're configured, ncurses will not recognize it, and you will see the escape character.

0
votes

Doh! I finally found there was an alias "alias cmd='TERM=Linux cmd'" in an old .bashrc file, so my TERM was set to linux only for the duration of the command. Stupid simple issue that took hours of debugging to figure out. Lesson learned.