用信号实现键盘的控制
2012-08-24 16:04
204 查看
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <signal.h>
#include "shapehead.h"
void timer(int signo)
{
printf("time : 1s\n");
alarm(1);
}
int main()
{ srand(time(NULL));
nextindex=randomshape();
drawframe();
//printnextshape();
start();
printf("\033[0m");
struct termios termios_p[1];
struct termios termios_backup[1];
tcgetattr(0, termios_p);
tcgetattr(0, termios_backup);
termios_p->c_lflag = termios_p->c_lflag & ~(ICANON | ECHO);
termios_p->c_cc[VMIN] = 1;
termios_p->c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, termios_p);
signal(SIGALRM, timer);
alarm(1);
while(1)
{
fflush(NULL);
int c = getchar();
if (c == 'q' || c == 'Q') return(0);
else if(c == 'w' || c == 'W') printf("UP\n");
else if(c == 's' || c == 'S') printf("DOWN\n");
else if(c == 'a' || c == 'A') printf("LEFT\n");
else if(c == 'd' || c == 'D') printf("RIGHT\n");
if(c == 0x5b)
{
c = getchar();
switch(c)
{
case 0x41: printf("up\n"); break;
case 0x42: printf("down\n"); break;
case 0x43: printf("right\n"); break;
case 0x44: moveleft(); break;
}
}
}
tesetattr(0, TCSANOW, termios_backup);
return 0;
}
#include <termios.h>
#include <unistd.h>
#include <signal.h>
#include "shapehead.h"
void timer(int signo)
{
printf("time : 1s\n");
alarm(1);
}
int main()
{ srand(time(NULL));
nextindex=randomshape();
drawframe();
//printnextshape();
start();
printf("\033[0m");
struct termios termios_p[1];
struct termios termios_backup[1];
tcgetattr(0, termios_p);
tcgetattr(0, termios_backup);
termios_p->c_lflag = termios_p->c_lflag & ~(ICANON | ECHO);
termios_p->c_cc[VMIN] = 1;
termios_p->c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, termios_p);
signal(SIGALRM, timer);
alarm(1);
while(1)
{
fflush(NULL);
int c = getchar();
if (c == 'q' || c == 'Q') return(0);
else if(c == 'w' || c == 'W') printf("UP\n");
else if(c == 's' || c == 'S') printf("DOWN\n");
else if(c == 'a' || c == 'A') printf("LEFT\n");
else if(c == 'd' || c == 'D') printf("RIGHT\n");
if(c == 0x5b)
{
c = getchar();
switch(c)
{
case 0x41: printf("up\n"); break;
case 0x42: printf("down\n"); break;
case 0x43: printf("right\n"); break;
case 0x44: moveleft(); break;
}
}
}
tesetattr(0, TCSANOW, termios_backup);
return 0;
}
相关文章推荐
- 感觉很流畅的js实现的键盘控制(带惯性)
- 简单远程控制(仅传递鼠标和键盘消息)的实现
- 简单远程控制(仅传递鼠标和键盘消息)的实现
- unity3d,制作自己的第一个射击游戏demo,实现镜头跟随和键盘控制移动
- 感觉很流畅的js实现的键盘控制(带惯性)
- JS实现用键盘控制div的移动操作与背景变色
- 如何实现一套鼠标键盘控制二台主机
- 实现鼠标点击及键盘控制下拉菜单事件
- FPGA 实现PS/2键盘控制LED
- 键盘控制事件是实现交互性最有力的方法之一
- javascript实现可键盘控制的抽奖系统
- javascript实现可键盘控制的抽奖系统
- js实现键盘的上下左右控制图片移动
- javascript实现ecshop搜索框键盘上下键切换控制
- unity 实现键盘控制物体移动和转向
- js实现按键球,小球随键盘上下左右控制移动
- 文字或图片跟随鼠标移动或键盘控制图片移动实例(javascript实现)
- js实现键盘控制移动div
- js实现键盘控制DIV移动的方法
- C# 实现键盘控制DateTimePicker日历控件下拉