我怎样才能得到绝对鼠标位置在Linux下用C [英] How can i get the absolute mouse position in Linux in C

查看:1935
本文介绍了我怎样才能得到绝对鼠标位置在Linux下用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知这两种方式来获得使用 libgpm 或阅读的/ dev /输入/小鼠文件。但后者只返回从最后一个位置的相对位置即可。所以我的问题是我如何能得到在绝对鼠标位置虽然读的/ dev /输入/小鼠或其他方式。

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.

我要落实 C C ++ 此功能。任何信息都将成为AP preciate。

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

推荐答案

首先,鼠标设备可能只发送相对运动,所以没有办法得到绝对位置(只是尝试用你的手,以提高鼠标把它放在其他地方),除由运动整合。

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.

和几乎所有的Linux GUI环境高于 X11 ,所以它是X11服务器(通常在的Xorg 过程)与鼠标(这是唯一的过程实际上读的/ dev /输入/老鼠涉及

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)

您会那么就需要做出X11客户端应用程序。请参见&放大器; 的问题。但你会在使用一些现有的工具库,比如QT或者GTK好得多;例如见 QMouseEvent &安培; QWidget的:: mouseMoveEvent Qt中和的 GtkWidget的运动通知事件GTK中的信号(和许多其他功能)。

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).

另请参阅

这篇关于我怎样才能得到绝对鼠标位置在Linux下用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆