bug-ncurses
[Top][All Lists]
Advanced

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

RE: Ncurses keypad is not properly working in FreeBSD


From: Brad Hines
Subject: RE: Ncurses keypad is not properly working in FreeBSD
Date: Mon, 23 Jan 2023 23:07:19 -0800

I’m not sure if this is related to your question or not, but perhaps it will help.

 

I had some issues with certain keycodes, and I recall that there’s something funny about xterm.  It may be that xterm is the source of your problems.  A quick and dirty thing to try would be to try a different terminal type.

 

 

I made a note in my code that I found this online that had some info, might be of help to you:

 

https://stackoverflow.com/questions/16975367/ncurses-reading-numpad-keys-and-escaping

 

That is solving a slightly different set of keys than I was worried about.  I am using CDK which is built on top of ncurses, but I ended up extending the already-defined key set with my own customer keys to define ALT-A to ALT-Z and then ALT-a to ALT-z.

 

 

 

 

 

From: help-ncurses-bounces+brad.hines=planeta.energy@gnu.org <help-ncurses-bounces+brad.hines=planeta.energy@gnu.org> On Behalf Of Archimedes Gaviola
Sent: Monday, January 23, 2023 8:09 PM
To: help-ncurses@gnu.org; bug-ncurses@gnu.org
Subject: Ncurses keypad is not properly working in FreeBSD

 

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]