help-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ncurses keypad is not properly working in FreeBSD


From: Archimedes Gaviola
Subject: Ncurses keypad is not properly working in FreeBSD
Date: Tue, 24 Jan 2023 12:09:08 +0800

Hi,

I have a C program that accepts and displays numeric characters in 0-9 only and with alphabet keys, function keys are expected not to respond to any code from the keyboard using keypad(). I simulated a plain Ncurses C program without a window and another one with a window using the newwin() function. The program without window works getting no response from alphabet keys as well as function keys, however the Enter/return key (ch == KEY_ENTER) is not working instead I use (ch == '\n') to get it to work. The backspace key (ch == KEY_BACKSPACE) is working. For the program with the window, I expect it to behave similar to the plain program but the function keys such F5 to F12 are showing codes on the screen as well as Insert, Delete, Page Up and Page Down keys are also showing codes. Only F1, F2, F3 and F4 are behaving expectedly. The same thing happens to the Enter/return and backspace keys I use (ch == '\n') and  (ch == '\b') to get them working.

I need your help in this case if there's something I missed in the Ncurses initialization parameters or maybe a sort of environment variable configuration problem with my FreeBSD OS. My FreeBSD system is using xterm.

pangi@siquijor:~ # echo $TERM
xterm

FreeBSD version: FreeBSD 14.0-CURRENT (arm64)

Ncurses version:
#define NCURSES_VERSION_MAJOR 6
#define NCURSES_VERSION_MINOR 2
#define NCURSES_VERSION_PATCH 20210220

1. Plain C program (without window)

#include <ncurses.h>

int main(void)
{
        initscr();
        keypad(stdscr, TRUE);
        noecho();

        int i;

        for (i=1; i<=14; i++)
        {
                int ch = getch();
                if ((ch == '1') || (ch == '2') || (ch == '3') \
                     || (ch == '4') || (ch == '5') || (ch == '6') \
                     || (ch == '7') || (ch == '8') || (ch == '9') \
                     || (ch == '0'))
                {
                        addch(ch);
                        refresh();
                } else {
                        --i;
                }

                //if (ch == KEY_ENTER) (not working)
                if (ch == '\n')
                {
                        printw("Return key is pressed.\n");
                }

                if (ch == KEY_BACKSPACE)
                {
                        printw("Backspace key is pressed.\n");
                }

        }
        endwin();
        return 0;
}

2. Plain C derived program (with window)

#include <ncurses.h>

int main(void)
{
        WINDOW *alpha;

        initscr();
        //keypad(stdscr, TRUE); (the same outcome with keypad(alpha, TRUE) below)
        keypad(alpha, TRUE);
        noecho();
        start_color();
        init_pair(1,COLOR_WHITE,COLOR_BLUE);

        alpha = newwin(0,0,0,0);
        if( alpha == NULL)
        {
                endwin();
                puts("Problem creating window");
                return(1);
        }

        wbkgd(alpha,COLOR_PAIR(1));
        wrefresh(alpha);

        int i;

        for (i=1; i<=14; i++)
        {
                int ch = wgetch(alpha);
                if ((ch == '1') || (ch == '2') || (ch == '3') \
                     || (ch == '4') || (ch == '5') || (ch == '6') \
                     || (ch == '7') || (ch == '8') || (ch == '9') \
                     || (ch == '0'))
                {
                        waddch(alpha,ch);
                        wrefresh(alpha);
                } else {
                        --i;
                }

                //if (ch == KEY_ENTER) (not working)
                if (ch == '\n')
                {
                        wprintw(alpha,"Return key is pressed.\n");
                }

                //if (ch == KEY_BACKSPACE) (not working)
                if (ch == '\b')
                {
                        wprintw(alpha,"Backspace key is pressed.\n");
                }

        }
        endwin();
        return 0;
}

Thanks and best regards,
Archimedes


reply via email to

[Prev in Thread] Current Thread [Next in Thread]