久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

如何在Linux中讀取低級鼠標單擊位置

瀏覽:95日期:2023-07-12 10:06:48
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決如何在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.code == 0) { rootX += ie.value; } else if (ie.code == 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.code == 272 ) { printf('Mouse button ');if (ie.value == 0) printf('released!!n');if (ie.value == 1) printf('pressed!!n'); } else {printf('time %ld.%06ldttype %dtcode %dtvalue %dn', ie.time.tv_sec, ie.time.tv_usec, ie.type, ie.code, ie.value); } } return 0;}解決方法

我正在使用此代碼從linux中的dev / input / event *讀取鼠標事件。

#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <linux/input.h>#include <fcntl.h>#define MOUSEFILE '/dev/input/event4'int main(){ int fd; struct input_event ie; if((fd = open(MOUSEFILE,O_RDONLY)) == -1) {perror('opening device');exit(EXIT_FAILURE); } while(read(fd,&ie,sizeof(struct input_event))) {printf('time %ld.%06ldttype %dtcode %dtvalue %dn',ie.time.tv_sec,ie.time.tv_usec,ie.type,ie.code,ie.value);} return 0;}

它給我的結果格式:

時間1342517261.840285類型2代碼0值-1

“時間”是時間戳,它返回事件發生的時間。

“代碼”是事件代碼,例如REL_X或KEY_BACKSPACE,完整列表位于include / linux / input.h中。

“價值”是事件帶來的價值。EV_REL的相對更改,EV_ABS(操縱桿…)的絕對新值,或EV_KEY的釋放為0,按鍵為1以及自動重復為2。

當我單擊時,我得到了事件,但沒有在屏幕上獲得鼠標的位置,如何在屏幕上獲得鼠標的位置。

編輯1:所以事實證明我必須使用相對坐標來獲取鼠標坐標。我相信這是一個普遍的要求,因此可能會有庫/預先存在的代碼可用于獲取坐標。關于該主題的任何信息將非常有用。

Edit2:解決方案

#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <linux/input.h>#include <fcntl.h>#include <X11/Xlib.h>#define MOUSEFILE '/dev/input/event4'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,sizeof(struct input_event))) { if (ie.type == 2) { if (ie.code == 0) { XQueryPointer(dpy,&mask); //rootX += ie.value; } else if (ie.code == 1) { XQueryPointer(dpy,&mask); // rootY += ie.value; } printf('time%ld.%06ldtx %dty %dn',rootX,rootY); } else printf('time %ld.%06ldttype %dtcode %dtvalue %dn',ie.value); } return 0;}

XQueryPointer似乎是更方便的解決方案。謝謝@perreal的指導。

標簽: Linux系統
相關文章:
主站蜘蛛池模板: 日韩成人 | 97高清国语自产拍 | 久久久久久国产精品高清 | 青青草在线视频免费观看 | 亚洲狠狠久久综合一区77777 | 99r精品在线 | 天天夜碰日日摸日日澡 | 亚洲午夜在线 | 成人免费高清 | 亚洲午夜精品 | 欧美xxxx性| 一区二区三区在线免费观看 | 中文字幕在线看第二 | 精品视频久久 | 欧美中文字幕在线 | 欧美一区二区三区 | 色图综合 | 中文字幕亚洲欧美日韩在线不卡 | 精品国产一区二区三区性色av | 中文字幕在线观看av | www.久久| 四虎动漫| 欧美成人一区二区 | 色综合一区二区三区 | 免费一二区 | 久久久久久免费 | 簧片免费网站 | 超碰日韩在线 | 一区二区中文字幕 | www.亚洲区 | 91佛爷在线观看 | 国产精品毛片一区二区三区 | 黄色骚片 | 国产精品视频播放 | 成人欧美一区二区三区白人 | 欧美国产综合一区 | 男女羞羞视频在线观看 | 91精品国产91久久久久久黑人 | 久久69精品久久久久久久电影好 | av中文字幕在线 | 日本一区二区视频 |