分类: C/C++
2008-03-11 09:05:17
#include <stdio.h>
#include <sys/ioctl.h>
#include <termios.h>
int getch( );
int main( )
{
char ch;
while(1){
ch = getch( );
printf("You Pressed %c\n", ch);
if(ch == 'E')
break;
}
}
int getch()
{
char ch;
struct termios save, ne;
ioctl(0, TCGETS, &save);
ioctl(0, TCGETS, &ne);
ne.c_lflag &= ~(ECHO | ICANON);
ioctl(0, TCSETS, &ne);
read(0, &ch, 1);
ioctl(0, TCSETS, &save);
return ch;
}