Ncurses-KEY_ENTER not working

I tried to teach myself ncurses, and I still love it. However, I am trying to write a small small text editor such as pico or nano. So far it has been good. I created a function to display keys. No matter what I do, I cannot get a response from KEY_ENTER. Whenever I click on it, it just jumps to the beginning of the current line I'm in. I tried using raw (); and use 13 instead of "KEY_ENTER" no luck. All other keys respond as expected. I would be grateful for any advice. I looked at it, trying to make it work forever. Thank you

    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);
}
+5
source share
4 answers

10 ASCII... ncurses. , , , , .

+4

Enter Enter . /M (13), . KEY_ENTER .

ncurses getch NOTES:

, , , KEY_ENTER /M, KEY_BACKSPACE /. , ( terminfo), terminfo. Ncurses terminfo. KEY_ENTER /M, getch KEY_ENTER /M.

, KEY_ENTER (), :

  • ,

  • Enter ASCII ,

  • , nl nonl, "Enter" , ,

  • " " .

, , 10. C '\n' ( '\r').

+3

PDCurses:

#define KEY_ENTER 0x157 /* enter or send (unreliable) */

nonl() raw().

nl nonl , ( ('\n') ). . nonl, , . , .

+1

KEY_ENTER, , KEY_ENTER 10 \n, ASCII.

#include <ncurses.h>
int main() {
    initscr();  /* init ncurses */
    keypad(stdscr, TRUE);   /* get keyboard input */
    addstr("Press enter to exit.\n");
    while (10 != getch()) {}    /* 10 == enter */
    endwin();   /* end ncurses */
    return 0;
}
0

All Articles