I am trying to create a program that response to keyboard input. At the moment the menu below functions correctly but upon pressing enter I am running into issues. When I press enter nothing happens. I am just wondering why this is happening? Many thanks!
#include <ncurses.h>
#define MENUMAX 6
void drawmenu(int item)
{
int c;
char mainmenu[] = "Menu";
char menu[MENUMAX] [10] = {
"1",
"2",
"3",
"4",
"5",
"6"
};
clear();
attron(A_BOLD | A_UNDERLINE);
addstr(mainmenu);
attroff(A_BOLD | A_UNDERLINE);
for( c = 0; c < MENUMAX; c++)
{
if( c == item)
attron(A_REVERSE);
attron(A_BOLD);
mvaddstr(3 + (c * 2), 20, menu[c]);
attroff(A_BOLD);
attroff(A_REVERSE);
}
refresh();
}
int main(int argc, char *argv[])
{
int key, menuitem;
menuitem = 0;
initscr();
drawmenu(menuitem);
keypad(stdscr, TRUE);
noecho();
do
{
raw();
nonl();
key = getch();
switch(key)
{
case KEY_DOWN:
menuitem++;
if(menuitem > MENUMAX - 1) menuitem = 0;
break;
case KEY_UP:
menuitem--;
if(menuitem < 0) menuitem = MENUMAX - 1;
break;
case KEY_ENTER:
mvaddstr(17, 25, "Test mesage!");
refresh();
break;
default:
break;
}
drawmenu(menuitem);
} while(key != '~');
echo();
endwin();
return 0;
}