|
发表于 2004-11-18 12:00:38
|
显示全部楼层
在 C 专家编程中有这样的描述。可以使用 stty 的特性实现:- #include <stdio.h>
- #include <sys/ioctl.h>
- int kbhit(void)
- {
- int i;
- ioctl(0, FIONREAD, &i);
- return i;
- }
- int main(void)
- {
- int i;
- int c = ' ';
- system("stty raw -echo");
- printf("enter 'q' to quit\n");
- for (i = 0; c != 'q'; i++) {
- if (kbhit()) {
- c = getchar();
- printf("\n got %c, on iteration %d\n", c, i);
- }
- }
- system("stty cooked echo");
- }
复制代码 |
|