Linux下所有获取屏幕输入底层都是此方法。
//获取屏幕坐标,0x03表示
//type EV_ABS 03 绝对坐标
// code ABS_MT_POSITION_X 0x35 绝对坐标值的x值
// code ABS_MT_POSITION_X 0x36 绝对坐标值的y值
#include <stdio.h>
#include <linux/input.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
int fd = open("/dev/input/event0",O_RDWR);
if(-1 ==fd )
{
perror(“open evetns0”);
return -1;
}
struct input_event ev;
while(1)
{ printf("======================\n");
read(fd, &ev, sizeof(ev));
if(ev.type == 0x3&& ev.code == 0x35)
{ x = ev.value;
printf("type:%u\t code:%u\tvalues:%d\n",
ev.type,ev.code,x);
}
if(ev.type == 0x3&& ev.code == 0x36)
{
y = ev.value;
printf("type:%u\t code:%u\tvalues:%d\n",
ev.type,ev.code,y);
}
printf("======================\n");
}
printf("Hello World!\n");
return 0;
}