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


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 <strong>relative position</strong> from the last position. So my question is how can i get the <strong>absolute mouse position</strong> though reading /dev/input/mice or other way.

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.

And almost all Linux GUI environments are above <a href="http://en.wikipedia.org/wiki/X11" rel="nofollow">X11</a>, 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 <a href="https://stackoverflow.com/q/9357382/841108" rel="nofollow">this</a> & <a href="https://stackoverflow.com/q/10311270/841108" rel="nofollow">that</a> question. But you'll be much better in using some existing toolkit library, like Qt or GTK; see e.g. <a href="http://doc.qt.digia.com/qt/qmoveevent.html" rel="nofollow">QMouseEvent</a> & <a href="http://doc.qt.digia.com/qt/qwidget.html#mouseMoveEvent" rel="nofollow">QWidget::mouseMoveEvent</a> in Qt, and <a href="http://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-motion-notify-event" rel="nofollow">GtkWidget "motion-notify-event" signal</a> in Gtk (and many other functions).

See also <a href="https://stackoverflow.com/q/14553435/841108" rel="nofollow">this question</a>


  • comparing two text file and find out the related word in python
  • List as a function argument - modifications discarded
  • Performance slowdown when using Julia's built-in functions
  • Parse text file and store fields in hash table in Perl
  • Google script to remove duplicate rows in spreadsheet and keep the most recent entry based on timest
  • lazy load plugin to load images as user scrolls?
  • Linux X11 C Want to know pointer motion anywhere on screen
  • how to request user permissions using facebook api in js?
  • Aframe: How do I link entities, so the user can link/unlink entities, and so entities will animate t
  • Python — confused by numpy's piecewise function
  • Recursive query with sub-graph aggregation
  • Return an average of last or first two rows from a different group (indicated by a variable)
  • .NET and Facebook Integration [closed]
  • Use Java program from Python
  • From where can I find App Secret in Dropbox for android?
  • Right reporting solution in a .Net environment
  • flickr, tumblr , instagram share intent in android
  • Add confidence intervals to GLM allEffects plot
  • error unknown avd
  • Strip down any parameter from URL which is not whitelisted
  • Count occurrences of strings in Java
  • moving an object without actually touching the object
  • Re-training inception google cloud stuck at global step 0
  • Renewing Cookie-session for express.js
  • How to Cache Images Dynamically-Generated with PHP?
  • D3 v4 force layout disable animation on drag
  • passing parameter to server in ExtJs
  • Recycler View Inside Recycler View not Scrolling
  • Jquery UI Sortable, move item automatically
  • retrieving data from url in iphone
  • Using MouseListener to select a range of cells in a grid
  • Android cannot disable cut copy paste
  • Eclipse MTJ doesn't see Java ME SDK 3.0 devices
  • blade.php method outputting it's result to the form
  • 550 Access denied - Invalid HELO name
  • Insert new calendar with SyncAdapter- Calendar API Android
  • Django simple Captcha “No module named fields” error
  • C# - Serializing and deserializing static member
  • Bug in WPF DataGrid
  • Sony Xperia Z Tablet not found by adb
  • How would I use PHP exceptions to define a redirect?
  • Incrementing object id automatically JS constructor (static method and variable)
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Can I make an Android app that runs a web view in Chrome 39?
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Web-crawler for facebook in python
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?