|
发表于 2006-8-30 09:15:10
|
显示全部楼层
其实就是做一个kbhit(),然后自己处理键盘输入
[code:1]
#include <sys/ioctl.h>
#include <stdio.h>
#include <termio.h>
#include <unistd.h>
#include <stdlib.h>
struct termio ttysave;
void restore()
{
if(ioctl(0, TCSETAF, &ttysave)==-1){
printf("restore error\n");
}
return;
}
int set_tty()
{
struct termio tty;
if(ioctl(0, TCGETA, &tty)==-1){
printf("error while setup tty\n");
return -1;
}
ttysave = tty;
tty.c_lflag &= ~(ICANON | ECHO| ISIG);
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 0;
if(ioctl(0, TCSETAF, &tty)==-1){
restore();
printf("error while setup tty\n");
return -1;
}
return 0;
}
int kbhit()
{
char ch;
read(0, &ch, 1);
return ch;
}
main()
{
set_tty();
while(1)
{
int a;
a=kbhit();
if(a>='a'&&a<='z')
{
printf("you press %c\n",a);
if(a=='q')
break;
}
else
printf("key code = %x\n",a);
}
restore();
}
[/code:1] |
|