How can i get the absolute mouse position in Linux in C

↘锁芯ラ 提交于 2019-12-24 16:33:02

问题


As far as i know the two ways to get mouse position are using libgpm or reading /dev/input/mice file. But the latter just returns a relative position from the last position. So my question is how can i get the absolute mouse position though reading /dev/input/mice or other way.

And i want to implement this function by C or C++. Any information will be appreciate.


回答1:


First, a mouse device is probably sending only relative movements, so there is no way to get the absolute position (just try to raise the mouse with your hand and put it elsewhere), except by integrating the movement.

And almost all Linux GUI environments are above X11, so it is the X11 server (usually the Xorg process) which deals with the mouse (it is the only process actually reading /dev/input/mice)

You'll then need to make an X11 client application. See this & that question. But you'll be much better in using some existing toolkit library, like Qt or GTK; see e.g. QMouseEvent & QWidget::mouseMoveEvent in Qt, and GtkWidget "motion-notify-event" signal in Gtk (and many other functions).

See also this question



来源:https://stackoverflow.com/questions/14556305/how-can-i-get-the-absolute-mouse-position-in-linux-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!