Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keys not being interpreted by ncurses

I have a curses based application (WordGrinder). I've just had a bug report from a user saying that some keys aren't working properly on his keyboard. On investigation, he's right.

The keys in question are SHIFT+cursor keys and some of the keypad navigation keys, such as END. Investigating what's going on, it seems that curses is not sending me events for these keys. In the case of SHIFT+cursor keys, I'm not getting anything at all, and for END I'm getting a raw escape sequence.

This surprises me. All the other keys are getting interpreted and translated correctly into keysyms. I'd expect to be getting KEY_SLEFT and KEY_END. Why aren't I?

I've looked at some other applications where these keys work but don't spot anything obvious that I'm doing wrong; and applications like nano do really evil things like handle their own escape key parsing anyway, so I don't know if they're a good candidate for source code.

I'm initialising ncurses as follows:

initscr();
raw();
noecho();
meta(NULL, TRUE);
nonl();
idlok(stdscr, TRUE);
idcok(stdscr, TRUE);
scrollok(stdscr, FALSE);
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);

I'm using gnome-terminal as the terminal emulator, and xterm as the terminal type. Locale is UTF-8 and I've got the ncursesw variant of the library.

Any ideas?

Update:

Well, many months later I try Wordgrinder with Gnome 3's gnome-terminal and discover that all these wacky keys generate valid ncurses keycodes. For example, SHIFT+LEFT now produces keycode 393. xterm produces exactly the same result. Unfortunately, CTRL+LEFT produces keycode 539, and the Curses documentation states clearly that valid keycodes are in the range KEY_MIN to KEY_MAX --- 257 to 511...

So at least things work now, but how do these weird new keycodes work? Are they defined anywhere? They're certainly not in the headers.

like image 262
David Given Avatar asked Nov 14 '22 20:11

David Given


1 Answers

gnome-terminal is not an xterm. It sends different combinations for shift-arrow and control-arrow. With ncurses version 5.5 setting TERM to gnome will probably work.

Here is some information: http://invisible-island.net/xterm/xterm.faq.html#bug_gnometerm

like image 96
Craig Avatar answered Dec 11 '22 08:12

Craig