I have used this as a replacement for the windows _getch.
You will need to include term.h on Linux.
Be aware, I understand there are problems with term.h inclusion and g++ ????
James
int _getch_(int waitkey)
{
struct termios initial_settings, new_settings;"
unsigned char ch;
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = waitkey;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
//read(0,&ch,1);
ch = getchar();
tcsetattr(0, TCSANOW, &initial_settings);
return ch;
}
You can also install & use ncurses library.
I have got the ncurses library. Simply using #include <ncurses.h> does not work. Should I include only curses.h to get getch() working?
I have used this as a replacement for the windows _getch.
You will need to include term.h on Linux.
Be aware, I understand there are problems with term.h inclusion and g++ ????
James
int _getch_(int waitkey)
{
struct termios initial_settings, new_settings;"
unsigned char ch;
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = waitkey;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
//read(0,&ch,1);
ch = getchar();
tcsetattr(0, TCSANOW, &initial_settings);
return ch;
}
I am getting an error in the first line (struct termios initial_settings, new_settings;"): /usr/include/c++/4.8/conio.h|470|error: missing terminating " character|
I tried removing " form the end and it resulted in these errors:
final.cpp|| undefined reference to `stdscr'|
final.cpp|| undefined reference to `wgetch'|
Gramercy...