- 积分
- 15
贡献60
飞刀13 FD
注册时间2020-3-24
在线时间2 小时
|
楼主 |
发表于 2020-3-24 16:55:09
|
显示全部楼层
这段代码可以控制鼠标移动,但是必须要插入鼠标,否则没有/dev/input/event2
网上的资料说,有一个用户输入设备 /dev/uinput,可是你们的系统里没有,ubuntu虚拟机里有,如何再嵌入式里增加uinput?
int fd_mouse = open("/dev/input/event2", O_RDWR);
if(fd_mouse <= 0)
{
printf("---------------error open mouse\n");
}
struct input_event event;
while(1)
{
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_REL;
event.code = REL_X;
event.value = 10;
write(fd_mouse, &event, sizeof(event));
event.type = EV_REL;
event.code = REL_Y;
event.value = 10;
write(fd_mouse, &event, sizeof(event));
// if(read(fd_mouse,&event,sizeof(input_event))<1) break;
printf("%d,%d,%d,%d\n",event.time.tv_sec,event.type,event.code,event.value);
event.type = EV_SYN;
event.code = 0;
event.value = 0;
write(fd_mouse, &event, sizeof(event));
sleep(1);
} |
|