如何在Linux中读取低级鼠标单击位置。

如何在Linux中读取低级鼠标单击位置。,第1张

如何在Linux中读取低级鼠标单击位置

您可以从X11获取初始位置,并使用相对坐标来跟踪指针

#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <linux/input.h>#include <fcntl.h>#include <X11/Xlib.h>#define MOUSEFILE "/dev/input/event6"int main(){  int fd;  struct input_event ie;  Display *dpy;  Window root, child;  int rootX, rootY, winX, winY;  unsigned int mask;  dpy = XOpenDisplay(NULL);  XQueryPointer(dpy,DefaultRootWindow(dpy),&root,&child,   &rootX,&rootY,&winX,&winY,&mask);  if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {    perror("opening device");    exit(EXIT_FAILURE);  }  while(read(fd, &ie, sizeof(struct input_event))) {    if (ie.type == 2) {      if (ie.pre == 0) { rootX += ie.value; }      else if (ie.pre == 1) { rootY += ie.value; }      printf("time%ld.%06ldtx %dty %dn",          ie.time.tv_sec, ie.time.tv_usec, rootX, rootY);    } else if (ie.type == 1) {      if (ie.pre == 272 ) {         printf("Mouse button ");        if (ie.value == 0) printf("released!!n");        if (ie.value == 1) printf("pressed!!n");    } else {        printf("time %ld.%06ldttype %dtpre %dtvalue %dn", ie.time.tv_sec, ie.time.tv_usec, ie.type, ie.pre, ie.value);    }  }  return 0;}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4899488.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存