July 10th, 2003, 04:51 PM
Hi new to Linux and c++
I'm trying to do a data enty prog (I'm using Linux 7 and gcc) and I'm using the ncurses library and when I try to use the f1 to f4 keys or use de 1,3,7,9 keys of the numeric pad (with the num lock on) the program exits. I tried to catch the value of those keys using wgetch, but they will not show on screen. What am I missing?. Thanks in advance for your input. Here's part of the code
# include <ncurses.h>
// cbreak(); (I TRY THIS AND RAW )
case KEY_F(1): I NEVER GET HERE
cout << "yuppy" << endl;
case 27: I GET HERE
case 9: i GET HERE
case 10: I GET HERE
July 13th, 2003, 12:29 PM
Try getting the value from case F1() beforehand, and using that value in case.
July 13th, 2003, 01:21 PM
The function keys usually donīt send "normal" key codes. The codes used are determined by your TERM variable and the kind of terminal you are using (see below). I am not sure if ncurses honors the TERM variable automatically, maybe you have to take care of it yourself. (TERM points to an entry in your /etc/termcap file that describes the special characters used by your terminal and also the available keys)
Probably the escape code is quitting your program. Where are you running it? (console, ssh, telnet, xterm, ...?)
July 14th, 2003, 01:21 PM
thanks for your answers folks
ygfperson: I tried to get the value, but the escape code
within the key makes the program to terminate
M.Hirsch: I'm using a prog called PuTTy using the telnet protocol. I tried my program in my computer and in the
server's console wiithout any change in the output.
I tried to read the /etc/termcap but is beyond my capabilities to interpret this file.
I don't need to use the F keys but when I pressed them
it cancels the prog. which is kind of annoying, in fact I want to cancel them.
The other keys 2,4,6,8 in the numeric keypad I realy need them, is there any way I can get their values, please help me. This is a project I have to turn in soon, and this is the only bug I have.
Thank's for your attention
July 14th, 2003, 02:31 PM
Iīm using putty too :)
Go to "Terminal / Keyboard" settings and play with the settings in the top group.
I am using "The function keys and keypad...": ESC[n~
But maybe you have to switch to "linux" or "xterm".
July 14th, 2003, 05:58 PM
didn't work, any other solutions ? or do you any partial code that worked for you
Thanks for everyting
July 15th, 2003, 11:49 AM
Sorry, I donīt have any working code. Itīs too long ago that I played with ncurses.
I tried to write one based on your code when it suddenly hit my head:
You want to quit here, right?
ESC (Ascii 27) starts the special key sequences, it is not used for the ESC key. The ESC key has a symbolic name like KEY_CANCEL. (not sure if this is the correct one, test it)
I guess it works now? :D
July 15th, 2003, 01:20 PM
your right, It was getting into the 27 (Esc) switch
but know, who can I capture the value of the key pressed so I can use it ??
I know I have became a burden, but I don't know where to look fo it, the books I have don't mention anything/
July 15th, 2003, 01:33 PM
All but the standard ascii keys (32..127) have to be encoded with KEY_* symbols.
I am not sure where in the documentation they are listed, have a look at /usr/include/ncurses.h ;)
July 15th, 2003, 04:03 PM
Hi M.Hirsch, still the same prob.
I took all the KEY__ of the ncurses.h and made a big switch case with a default clause, so I can figure out which case the teky 2,4,6,8 will get and it still goes to the default clause. I still can catch the value of these keys.
sorry, but any other idea ??
July 16th, 2003, 01:06 PM
This doesnīt work. The delays are necessary to detect the special keys. This way the program can find out if the received characters were pressed one after the other or if they belong to one sequence the library takes care of that).
Remove this line and it will do just fine :)
PS: I am using "TERM=xterm" in my .profile and putty set to "Xterm R6" too.