Unix Programming - ncurses: F1-F8 keys

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > August 2004 > ncurses: F1-F8 keys





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author ncurses: F1-F8 keys
vertigo

2004-08-23, 8:01 am

Hello
I found that KEY_F(int n) returns me codes for keys F1-F8, but
the problem is that when i read getchar() i receive codes:
F1 126
F2 126
F3 126
F4 126
F5 269
F6 270
F7 271
F8 272

Why for F1-F4 keys i always receive the same code ?
I use 5.1-RELEASE-p16, default installation.

Thanx
Michal

vertigo

2004-08-23, 8:01 am


Maybe i show the code which i used to test that values:

int main(void){
int key;
initscr();
crmode();
keypad(stdscr,TRUE);
noecho();
clear();

mvprintw(5,5,"Demo, type q to quit");
move(7,5);
refresh();

key=getch();
while(key!=ERR && key!='q'){
move(7,5);
clrtoeol();
printw("Key code: %d",key);
refresh();
key=getch();
}
endwin();
exit(0);
}

Why do i have strange values for F1-F4 = 126 ??



Floyd L. Davidson

2004-08-23, 8:01 am

vertigo <none@microsoft.com> wrote:
>int main(void){
> int key;
> initscr();
> crmode();
> keypad(stdscr,TRUE);
> noecho();
> clear();
>
> mvprintw(5,5,"Demo, type q to quit");
> move(7,5);
> refresh();
>
> key=getch();
> while(key!=ERR && key!='q'){
> move(7,5);
> clrtoeol();
> printw("Key code: %d",key);
> refresh();
> key=getch();
> }
> endwin();
> exit(0);
>}


I tested your code (after reformatting to make it readable, and
adding includes for the appropriate header files) on a Linux box.

I could get the same effect you describe by running it in an
xterm and using either TERM=linux or TERM=xterm.

If it is run on a virtual console, with TERM=linux, it provides
unique codes for each function key. Likewise if run from xterm
with TERM=xterm-color it also provides unique (though very
different) codes for the function keys.

I didn't check to see what version of ncurses I have, and I
don't know exactly how old my terminfo database definitions for
those specific terminals are, or if they have been locally
modified or not.

None of that probably makes any difference though, as it appears
the point is that matching the TERM definition to the actual
terminal in use is essential!

--
FloydL. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com