#include "key.h" #include #include #include #include #define KEY_FD 0 static struct termios term_bak; void cui_key_enter(void) { struct termios raw; tcgetattr(KEY_FD, &term_bak); cfmakeraw(&raw); raw.c_lflag &= ~FLUSHO; tcsetattr(KEY_FD, TCSANOW, &raw); } void cui_key_exit(void) { tcsetattr(KEY_FD, TCSANOW, &term_bak); } int cui_key_get(void) { fd_set rfs; struct timeval tm; int ret; unsigned char uc; FD_ZERO(&rfs); FD_SET(KEY_FD, &rfs); tm.tv_sec = 0; tm.tv_usec = 100*1000; ret = select(KEY_FD+1, &rfs, NULL, NULL, &tm); if(ret <= 0) return 0; if(read(KEY_FD, &uc, 1) != 1) return 0; return uc; } /* EOF */