效果图:
代码:
#include#include #include #include #include #include int main(int argc, char const *argv[]) { struct input_event input_buf; int fd, x, y; int flag_ts = 0; int len = 0; //open virtual screen device fd = open("/dev/ubuntu_event",O_RDWR); if(fd < 0) { perror("open ts"); return -1; } while(1) { //read direction len = read(fd, &input_buf,sizeof(input_buf)); if (len < 0) { perror("read us"); return -1; } //判断是否绝对坐标值,EV_ABS,也就是触摸屏事件 //判断是返回的是X坐标还是Y坐标 if (input_buf.type == EV_ABS && input_buf.code == ABS_X) { x = input_buf.value; flag_ts|=0x01; } //判断是否绝对坐标值,EV_ABS,也就是触摸屏事件 //判断是返回的是X坐标还是Y坐标 if (input_buf.type == EV_ABS && input_buf.code ==ABS_Y) { y = input_buf.value; flag_ts|=0x02; } //x、y坐标获取完成 if (flag_ts==0x03) { printf("x=%d y=%drn", x, y); flag_ts = 0; } //延时10ms usleep(10*1000); } return 0; }



