I am building a simple game using the ncurses library, and am using keyboard input to move my character. I am currently reading this with getch(), but this is sub-optimal for two reasons:
The key does not send continuously when pressed, only a short period afterwards.
When continuously sending, is isn't always recognised by the system.
Is there an alternative to getch() which I am able to use?
Sample code demonstrating the effect:
#include <stdio.h>
#include <windows.h>
#include "curses.h"
void setup_screen();
int main() {
setup_screen();
while (true) {
fprintf(stderr, "%d\n", getch());
Sleep(20);
}
endwin();
return 0;
}
void setup_screen() {
initscr();
noecho();
curs_set( 0 );
timeout( 0 );
keypad( stdscr, TRUE );
clear();
}
Sample output:
...
260
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
260
260
-1
260
260
-1
260
-1
260
260
-1