Newer
Older
#include<sys/select.h>
#include<sys/ioctl.h>
int _kbhit(){
int kbhits;
ioctl(0, FIONREAD, &kbhits);
return kbhits;
}
//struct termios info; // This is from stackoverflow
//tcgetattr(0, &info); /* get current terminal attirbutes; 0 is the file descriptor for stdin */
//info.c_lflag &= ~ICANON; /* disable canonical mode */
//info.c_cc[VMIN] = 1; /* don't wait for keypress, return EOF instead */
//info.c_cc[VTIME] = 1; /* no timeout */
//info.c_cc[ECHO] = 0; //Turn off echo
//tcsetattr(0, TCSANOW, &info); /* set immediately */
//initscr();
//noecho();
//cbreak();
//scrollok(stdscr, true);
//nodelay(stdscr, true);
struct termios info;
tcgetattr(0, &info); //get attr
info.c_lflag &= ~ICANON; //turn off canonical mode
info.c_lflag &= ~ECHO;
tcsetattr(0, TCSANOW, &info); //set attr
setbuf(stdin, NULL); //???
int c = 0;
printf("\nint: %d\nchar: %c\nkbhit: %d\n", c, c, l);