On Sun, Apr 04, 2010 at 06:09:21AM -0400, Thomas Dickey wrote: > An application can use these by a tigetstr to check existence, e.g., > > char *s; > > s = tigetstr("kDC6"); > if (s != 0 && (long)(s) != -1) { > /* use the value */ > } > > ncurses decides that any of these strings that begin with "k" are > (by convention...) key names, and if > > use_extended_names(TRUE); > > was called, adds them to the table that getch uses to decode keys. > ncurses generates a keycode for these extended strings, and will > return that number. > > An application can make its own list of these keycodes by using > key_defined() for the by-convention names kDN6, kUP5, etc. The > keyname() function also can be used, on the value from getch(), to > get the name of the key. Thanks for the information. I'm almost able to get this working. Using use_extended_names(TRUE) now returns a single keycode for ctrl+<UP> (kUP5). However, both tigetstr() and key_defined() don't report that kUP5 is available (see attached program). The stock xterm terminfo entries don't have the kUP5, etc., definitions, so I did this: $ gunzip -d /usr/share/doc/xterm/xterm.terminfo.gz > ~/xterm.terminfo $ tic -x ~/xterm.terminfo $ export TERMINFO=$HOME/.terminfo $ export TERM=xterm-new `infocmp -x` now shows the kUP5 entry. Environment: Ubuntu 9.10 /ncurses 5.7
#include <ncursesw/ncurses.h> static struct key { char *name; int code; } Keys[] = { { "kUP5", 0 }, { "kDN5", 0 }, { 0, 0 } }; int main(void) { int i; initscr(); cbreak(); noecho(); nonl(); keypad(stdscr,TRUE); use_extended_names(TRUE); char *s = tigetstr("kUP5"); if (s && (long)(s) != -1) { printf("tigetstr for kUP5=%d\n", (long)s); } s = tigetstr("kDN5"); for (i=0;Keys[i].name;++i) { int code = key_defined(Keys[i].name); if (code > 0) { Keys[i].code = code; } } addstr("press a key"); int ch = getch(); endwin(); printf("keypress=%d\n", ch); for (i=0;Keys[i].name;++i) { printf("key=%s, code=%d\n", Keys[i].name, Keys[i].code); } exit(0); }
Attachment:
pgpI3YatEIbGU.pgp
Description: PGP signature