Created
September 23, 2011 10:24
-
-
Save rkumar/1237091 to your computer and use it in GitHub Desktop.
ncurses, use_extended_names, trapping Control-arrow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <ncursesw/ncurses.h> | |
/* gcc -o keytest -I/opt/local/include -lncurses keytest.c */ | |
/* TERM=xterm ./keytest | |
Try Control-left, Sh-F9, Control-UP, etc | |
* */ | |
static struct key { | |
char *name; | |
int code; | |
} Keys[] = { | |
{ "kLFT5", 0 }, | |
{ "kEND5", 0 }, | |
{ "kHOM5", 0 }, | |
{ "kHOM3", 0 }, | |
{ "kUP5", 0 }, | |
{ "kDN5", 0 }, | |
{ 0, 0 } | |
}; | |
int main(void) | |
{ | |
int i; | |
use_extended_names(TRUE); | |
initscr(); | |
cbreak(); | |
noecho(); | |
nonl(); | |
keypad(stdscr,TRUE); | |
for (i = 0; Keys[i].name != 0; ++i) { | |
int code; | |
char *s = tigetstr(Keys[i].name); | |
if (s && (long)(s) != -1) { | |
printw("tigetstr for %s=%s\n", Keys[i].name, s); | |
code = key_defined(s); | |
if (code > 0) { | |
Keys[i].code = code; | |
} | |
} | |
} | |
addstr("press a key"); | |
int ch = getch(); | |
int ch1 = getch(); | |
int ch2 = getch(); | |
int ch3 = getch(); | |
endwin(); | |
printf("keypress=%d\n", ch); | |
printf("keypress=%d\n", ch1); | |
printf("keypress=%d\n", ch2); | |
printf("keypress=%d\n", ch3); | |
for (i=0;Keys[i].name;++i) { | |
printf("key=%s, code=%d\n", Keys[i].name, Keys[i].code); | |
} | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment