ncurses- KEY_ENTER is fail

Jaron Bradley picture Jaron Bradley · Jun 17, 2012 · Viewed 18.1k times · Source

I've been trying to teach myself ncurses and I'm loving it so far. However, I'm trying to write a small little text editor like pico or nano. I've got it set up fairly well so far. I created a function to map the keys. No matter what I do I can not get a response from KEY_ENTER. Whenever I press it it just goes to the beginning of the currently line that I'm on. I've tried using raw(); and using 13 instead of "KEY_ENTER" no luck. All the other keys respond as expected. I would appreciate any advice. I've been staring at this trying to make it work forever. Thanks!

    void keymaps(){

    int ch;
    keypad(stdscr,TRUE);
       case KEY_UP:
            addstr("Up\n");
            break;
        case KEY_LEFT:
            addstr("Left\n");
            break;
        case KEY_RIGHT:
            addstr("Right\n");
            break;
        case KEY_BACKSPACE:
            delch();
            break;
        case Key_Enter:
            addstr("You pressed Enter\n");
        default:
            break;
        }
        refresh();
    } while(ch != KEY_HOME);
}

Answer

CodeIngot picture CodeIngot · Aug 9, 2015

Try 10 as ASCII value ... worked for me on ncurses.Also please update the actual code because this code that you put is wrong by syntax.