If echo
is on before the getch
call, ncurses may return ASCII backspace, e.g., 8 (same as \b
). That is mentioned in the source-code as a feature for Solaris compatibility:
/*
* If echo() is in effect, display the printable version of the
* key on the screen. Carriage return and backspace are treated
* specially by Solaris curses:
*
* If carriage return is defined as a function key in the
* terminfo, e.g., kent, then Solaris may return either ^J (or ^M
* if nonl() is set) or KEY_ENTER depending on the echo() mode.
* We echo before translating carriage return based on nonl(),
* since the visual result simply moves the cursor to column 0.
*
* Backspace is a different matter. Solaris curses does not
* translate it to KEY_BACKSPACE if kbs=^H. This does not depend
* on the stty modes, but appears to be a hardcoded special case.
* This is a difference from ncurses, which uses the terminfo entry.
* However, we provide the same visual result as Solaris, moving the
* cursor to the left.
*/
if (sp->_echo && !(win->_flags & _ISPAD)) {
chtype backup = (chtype) ((ch == KEY_BACKSPACE) ? '\b' : ch);
if (backup < KEY_MIN)
wechochar(win, backup);
}
Another possibility is that the terminal description (terminfo) may not agree with the actual terminal settings (stty). In that case, ncurses will return whatever the key happens to send (whether it is ASCII DEL / 127 or BS / 8 depends on the system you are using).