I'm writing a Tetris game with ncurses getting keyboard input with getch(). For the finished game nodelay() will be active but for testing purposes I have it commented out. For some reason the input function called by my game loop is ignoring every second character. For instance an input of 'q' closes my program. If I enter a sequence of aqaqaqaqaq... the program will never close because the q's do not register. Below is the function that init's my ncurses code and below that is my input function.
Edit: In case it matters I'm testing the code in Ubuntu running in virtualbox on Windows.
****INIT FUNCTION****
void init_ui()
{
initscr();
cbreak();
raw();
keypad(stdscr, TRUE);
noecho();
//nodelay(stdscr, TRUE);
start_color();
init_pair(9, COLOR_BLACK, COLOR_RED);
init_pair(2, COLOR_BLACK, COLOR_WHITE);
init_pair(3, COLOR_BLACK, COLOR_CYAN);
init_pair(4, COLOR_BLACK, COLOR_YELLOW);
init_pair(5, COLOR_BLACK, COLOR_MAGENTA);
init_pair(6, COLOR_BLACK, COLOR_BLUE);
init_pair(7, COLOR_BLACK, COLOR_GREEN);
init_pair(8, COLOR_BLACK, COLOR_BLACK);
attron(COLOR_PAIR(6));
for(int i=0; i<HEIGHT; i++)
{
mvprintw(i, 0, "#%*c", WIDTH*2+1, '#');
}
for(int i=0; i<=WIDTH; i++)
{
mvprintw(HEIGHT, i*2, "##");
}
attroff(COLOR_PAIR(6));
}
****INPUT FUNCTION****
int get_input()
{
int ch = getch();
int result;
switch(ch)
{
case KEY_LEFT:
result = LEFT;
break;
case KEY_RIGHT:
result = RIGHT;
break;
case KEY_DOWN:
result = DOWN;
break;
case 'q':
result = 'q';
break;
default:
result = DOWN;
break;
}
return result;
}