i have written simple program detect key press event. up, down, left, right , esc key returning 27!! can not differentiate, key has pressed.
#include<iostream> #include<stdio.h> #include<termios.h> using namespace std; static struct termios oldsettings,newsettings; void inittermios(bool echo) { tcgetattr(0,&oldsettings); newsettings=oldsettings; newsettings.c_lflag &=~icanon; newsettings.c_lflag &= echo ? echo : ~echo; tcsetattr(0,tcsanow,&newsettings); } void resettermios(void) { tcsetattr(0,tcsanow,&oldsettings); } char getch(bool echo) { inittermios(echo); char c=getchar(); resettermios(); return c; } int main() { int i=getch(false); cout<<i<<endl; return 0; }
what suppose remove ambiguity ??
Comments
Post a Comment