RE: Ncurses keypad is not properly working in FreeBSD
"Brad Hines" <[email protected]> Mon, 23 Jan 2023 23:07:19 -0800
| Newsgroups | gmane.comp.lib.ncurses.general,gmane.comp.lib.ncurses.bugs |
|---|---|
| Organization | Planet A Energy |
| Message-ID | <[email protected]> |
This is a multipart message in MIME format. ------=_NextPart_000_0F28_01D92F7F.7245CF30 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable I=E2=80=99m not sure if this is related to your question or not, but = perhaps it will help. =20 I had some issues with certain keycodes, and I recall that = there=E2=80=99s 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. =20 =20 I made a note in my code that I found this online that had some info, = might be of help to you: =20 https://stackoverflow.com/questions/16975367/ncurses-reading-numpad-keys-= and-escaping =20 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. =20 =20 =20 =20 =20 From: [email protected] = <[email protected]> On Behalf Of = Archimedes Gaviola Sent: Monday, January 23, 2023 8:09 PM To: [email protected]; [email protected] Subject: Ncurses keypad is not properly working in FreeBSD =20 Hi, =20 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 =3D=3D KEY_ENTER) is not working instead I use (ch = =3D=3D '\n') to get it to work. The backspace key (ch =3D=3D = 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 =3D=3D '\n') and (ch =3D=3D '\b') to get them = working. =20 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. =20 pangi@siquijor:~ # echo $TERM xterm =20 FreeBSD version: FreeBSD 14.0-CURRENT (arm64) =20 Ncurses version: #define NCURSES_VERSION_MAJOR 6 #define NCURSES_VERSION_MINOR 2 #define NCURSES_VERSION_PATCH 20210220 =20 1. Plain C program (without window) =20 #include <ncurses.h> int main(void) { initscr(); keypad(stdscr, TRUE); noecho(); int i; for (i=3D1; i<=3D14; i++) { int ch =3D getch(); if ((ch =3D=3D '1') || (ch =3D=3D '2') || (ch =3D=3D = '3') \ || (ch =3D=3D '4') || (ch =3D=3D '5') || (ch =3D=3D = '6') \ || (ch =3D=3D '7') || (ch =3D=3D '8') || (ch =3D=3D = '9') \ || (ch =3D=3D '0')) { addch(ch); refresh(); } else { --i; } //if (ch =3D=3D KEY_ENTER) (not working) if (ch =3D=3D '\n') { printw("Return key is pressed.\n"); } if (ch =3D=3D KEY_BACKSPACE) { printw("Backspace key is pressed.\n"); } } endwin(); return 0; } =20 2. Plain C derived program (with window) =20 #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 =3D newwin(0,0,0,0); if( alpha =3D=3D NULL) { endwin(); puts("Problem creating window"); return(1); } wbkgd(alpha,COLOR_PAIR(1)); wrefresh(alpha); int i; for (i=3D1; i<=3D14; i++) { int ch =3D wgetch(alpha); if ((ch =3D=3D '1') || (ch =3D=3D '2') || (ch =3D=3D = '3') \ || (ch =3D=3D '4') || (ch =3D=3D '5') || (ch =3D=3D = '6') \ || (ch =3D=3D '7') || (ch =3D=3D '8') || (ch =3D=3D = '9') \ || (ch =3D=3D '0')) { waddch(alpha,ch); wrefresh(alpha); } else { --i; } //if (ch =3D=3D KEY_ENTER) (not working) if (ch =3D=3D '\n') { wprintw(alpha,"Return key is pressed.\n"); } //if (ch =3D=3D KEY_BACKSPACE) (not working) if (ch =3D=3D '\b') { wprintw(alpha,"Backspace key is pressed.\n"); } } endwin(); return 0; } =20 Thanks and best regards, Archimedes =20 ------=_NextPart_000_0F28_01D92F7F.7245CF30 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" = xmlns:o=3D"urn:schemas-microsoft-com:office:office" = xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" = xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta = http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta = name=3DGenerator content=3D"Microsoft Word 15 (filtered = medium)"><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; font-size:11.0pt; font-family:"Calibri",sans-serif;} a:link, span.MsoHyperlink {mso-style-priority:99; color:#0563C1; text-decoration:underline;} span.EmailStyle18 {mso-style-type:personal-reply; font-family:"Calibri",sans-serif; color:windowtext;} .MsoChpDefault {mso-style-type:export-only; font-family:"Calibri",sans-serif;} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 9]><xml> <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--></head><body lang=3DEN-US = link=3D"#0563C1" vlink=3D"#954F72" style=3D'word-wrap:break-word'><div = class=3DWordSection1><p class=3DMsoNormal>I=E2=80=99m not sure if this = is related to your question or not, but perhaps it will = help.<o:p></o:p></p><p class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal>I had some issues with certain keycodes, and I recall = that there=E2=80=99s something funny about xterm. =C2=A0It may be that = xterm is the source of your problems.=C2=A0 A quick and dirty thing to = try would be to try a different terminal type.<o:p></o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p class=3DMsoNormal>I made a = note in my code that I found this online that had some info, might be of = help to you:<o:p></o:p></p><p class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal><a = href=3D"https://stackoverflow.com/questions/16975367/ncurses-reading-nump= ad-keys-and-escaping">https://stackoverflow.com/questions/16975367/ncurse= s-reading-numpad-keys-and-escaping</a><o:p></o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p class=3DMsoNormal>That is = solving a slightly different set of keys than I was worried about.=C2=A0 = 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.<o:p></o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><p = class=3DMsoNormal><o:p> </o:p></p><div = style=3D'border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in = 0in 0in'><p class=3DMsoNormal><b>From:</b> = [email protected] = <[email protected]> <b>On = Behalf Of </b>Archimedes Gaviola<br><b>Sent:</b> Monday, January 23, = 2023 8:09 PM<br><b>To:</b> [email protected]; = [email protected]<br><b>Subject:</b> Ncurses keypad is not properly = working in FreeBSD<o:p></o:p></p></div><p = class=3DMsoNormal><o:p> </o:p></p><div><div><p = class=3DMsoNormal>Hi,<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p class=3DMsoNormal>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 =3D=3D KEY_ENTER) is not working instead I use (ch = =3D=3D '\n') to get it to work. The backspace key (ch =3D=3D = 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 =3D=3D '\n') and (ch =3D=3D '\b') to get = them working.<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p class=3DMsoNormal>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.<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>pangi@siquijor:~ # echo = $TERM<br>xterm<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>FreeBSD version: FreeBSD 14.0-CURRENT = (arm64)<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>Ncurses version:<o:p></o:p></p></div><div><p = class=3DMsoNormal>#define NCURSES_VERSION_MAJOR 6<br>#define = NCURSES_VERSION_MINOR 2<br>#define NCURSES_VERSION_PATCH = 20210220<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>1. Plain C program (without = window)<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>#include <ncurses.h><br><br>int = main(void)<br>{<br> initscr();<br> = keypad(stdscr, TRUE);<br> = noecho();<br><br> int i;<br><br> = for (i=3D1; i<=3D14; i++)<br> = {<br> = int ch =3D getch();<br> = if ((ch =3D=3D '1') || (ch =3D=3D '2') || (ch =3D=3D '3') = \<br> = || (ch =3D=3D '4') || (ch =3D=3D '5') || (ch =3D=3D '6') = \<br> = || (ch =3D=3D '7') || (ch =3D=3D '8') || (ch =3D=3D '9') = \<br> = || (ch =3D=3D '0'))<br> = {<br> = addch(ch);<br> = = refresh();<br> } = else {<br> = --i;<br> = }<br><br> = //if (ch =3D=3D KEY_ENTER) (not working)<br> = if (ch =3D=3D '\n')<br> = {<br> = = printw("Return key is pressed.\n");<br> = }<br><br> = if (ch =3D=3D KEY_BACKSPACE)<br> = {<br> = = printw("Backspace key is pressed.\n");<br> = }<br><br> = }<br> endwin();<br> = return 0;<br>}<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>2. Plain C derived program (with = window)<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>#include <ncurses.h><br><br>int = main(void)<br>{<br> WINDOW = *alpha;<br><br> initscr();<br> = //keypad(stdscr, TRUE); (the same outcome with = keypad(alpha, TRUE) below)<br> keypad(alpha, = TRUE);<br> noecho();<br> = start_color();<br> = init_pair(1,COLOR_WHITE,COLOR_BLUE);<br><br> = alpha =3D newwin(0,0,0,0);<br> if( alpha = =3D=3D NULL)<br> {<br> = endwin();<br> = puts("Problem creating = window");<br> = return(1);<br> }<br><br> = wbkgd(alpha,COLOR_PAIR(1));<br> = wrefresh(alpha);<br><br> int i;<br><br> = for (i=3D1; i<=3D14; i++)<br> = {<br> = int ch =3D wgetch(alpha);<br> = if ((ch =3D=3D '1') || (ch =3D=3D '2') || (ch = =3D=3D '3') \<br> = || (ch =3D=3D '4') || (ch =3D=3D '5') || (ch =3D=3D = '6') \<br> = || (ch =3D=3D '7') || (ch =3D=3D '8') || (ch =3D=3D '9') = \<br> = || (ch =3D=3D '0'))<br> = {<br> = waddch(alpha,ch);<br> = = wrefresh(alpha);<br> = } else {<br> = --i;<br> = }<br><br> = //if (ch =3D=3D KEY_ENTER) (not = working)<br> if = (ch =3D=3D '\n')<br> = {<br> = wprintw(alpha,"Return key is = pressed.\n");<br> = }<br><br> = //if (ch =3D=3D KEY_BACKSPACE) (not working)<br> = if (ch =3D=3D '\b')<br> = {<br> = = wprintw(alpha,"Backspace key is pressed.\n");<br> = }<br><br> = }<br> endwin();<br> = return 0;<br>}<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div><div><p = class=3DMsoNormal>Thanks and best regards,<o:p></o:p></p></div><div><p = class=3DMsoNormal>Archimedes<o:p></o:p></p></div><div><p = class=3DMsoNormal><o:p> </o:p></p></div></div></div></body></html> ------=_NextPart_000_0F28_01D92F7F.7245CF30--