Thread: ncurses

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    tijuana
    Posts
    5
    Rep Power
    0

    ncurses


    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>

    WINDOW *win;
    initscr();
    keypad(f_win,TRUE);
    nodelay(f_win,FALSE);
    // cbreak(); (I TRY THIS AND RAW )
    raw();
    noecho();

    tecla=wgetch(f_win);
    switch(tecla)
    {
    case KEY_F(1): I NEVER GET HERE
    cout << "yuppy" << endl;
    break;
    case 27: I GET HERE
    break;
    case 9: i GET HERE
    break;
    case 10: I GET HERE
    case KEY_ENTER:
    case KEY_DOWN:
    ETC..
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    10
    Rep Power
    0
    Try getting the value from case F1() beforehand, and using that value in case.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    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, ...?)
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    tijuana
    Posts
    5
    Rep Power
    0
    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

    Salvador
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    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".
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    tijuana
    Posts
    5
    Rep Power
    0
    M.Hirsch
    didn't work, any other solutions ? or do you any partial code that worked for you

    Thanks for everyting

    Salvador
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    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:
    case 27: I GET HERE
    break;
    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
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    tijuana
    Posts
    5
    Rep Power
    0
    hi M.Hirsch,
    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/


    Thanks

    Salvador
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    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 ;)
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    tijuana
    Posts
    5
    Rep Power
    0
    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 ??

    Salvador
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190

    Smile Got it


    nodelay(f_win,FALSE);
    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.

IMN logo majestic logo threadwatch logo seochat tools logo