#include
#include
#include
#include
#include
#include
#include
int simkey(int fd,int value);
int main(void)
{
int fd_kbd;
char c;
if((fd_kbd=open("/dev/input/event1",O_RDWR ))<=0)
//ls /dev/input/event1是存在的
{
printf("can not open kbd file !\n");
return -1;
}
if(simkey(fd_kbd,1)<0)
{
printf("No press !\n");
return -1;
}
if(simkey(fd_kbd,0)<0)
{
printf("No release!\n");
return -1;
}
close(fd_kbd);
printf("YES!\n");
return 0;
}
int simkey(int fd,int value)
{
struct input_event event;
event.type=EV_KEY;
event.code=KEY_A; //模拟输入'A'
event.value=value;
gettimeofday(&event.time,0);
if(write(fd,&event,sizeof(event))<0)
{
printf("simulate key error! \n");
return -1;
}
return 0;
}
使用sudo执行即可[luther.gliethttp]
阅读(1428) | 评论(0) | 转发(0) |