分类: LINUX
2013-01-19 15:55:16
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void simulate_ctrl_space(int fd)
{
struct input_event event;
//先发送一个 CTRL 按下去的事件。
event.type = EV_KEY;
event.value = 1;
event.code = KEY_LEFTCTRL;
gettimeofday(&event.time,0);
write(fd,&event,sizeof(event)) ;
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
//先发送一个 SPACE 按下去的事件。
event.type = EV_KEY;
event.value = 1;
event.code = KEY_SPACE;
gettimeofday(&event.time,0);
write(fd,&event,sizeof(event)) ;
//发送一个 释放 SPACE 的事件
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_KEY;
event.code = KEY_SPACE;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
//发送一个 释放 CTRL 的事件
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_KEY;
event.code = KEY_LEFTCTRL;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
}
void simulate_ctrl_shift(int fd)
{
struct input_event event;
//先发送一个 CTRL 按下去的事件。
event.type = EV_KEY;
event.value = 1;
event.code = KEY_LEFTCTRL;
gettimeofday(&event.time,0);
write(fd,&event,sizeof(event)) ;
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
//先发送一个 SHIFT 按下去的事件。
event.type = EV_KEY;
event.value = 1;
event.code = KEY_LEFTSHIFT;
gettimeofday(&event.time,0);
write(fd,&event,sizeof(event)) ;
//发送一个 释放 SHIFT 的事件
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_KEY;
event.code = KEY_LEFTSHIFT;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
//发送一个 释放 CTRL 的事件
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_KEY;
event.code = KEY_LEFTCTRL;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
}
void simulate_ts(int fd)
{
struct input_event event;
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = 3;
event.code = 0;
event.value = 431;
write(fd, &event, sizeof(event));
event.type = 3;
event.code = 1;
event.value = 496;
write(fd, &event, sizeof(event));
event.type = 3;
event.code = 24;
event.value = 127;
write(fd, &event, sizeof(event));
event.type = 1;
event.code = 330;
event.value = 1;
write(fd, &event, sizeof(event));
event.type = 0;
event.code = 0;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = 3;
event.code = 24;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = 1;
event.code = 330;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = 0;
event.code = 0;
event.value = 0;
write(fd, &event, sizeof(event));
}
int main(int argc, char* argv[])
{
int fd_ts;
fd_ts = open("/dev/input/event0", O_RDWR);
if(fd_ts<=0){
printf("error open mouse\n");
return -2;
}
if(strcmp(argv[1],"space")==0)
{
fprintf(stderr,"ctrl+space\n");
simulate_ctrl_space(fd_ts);
}
else if(strcmp(argv[1],"shift")==0)
{
fprintf(stderr,"ctrl+shift\n");
simulate_ctrl_shift(fd_ts);
}
close(fd_ts);
}