How to Get Coordinates of the Linux Cursor

Interacting with the Windows system of any given operating system can be accomplished in many of the languages that the system supports. What language you will use will depend on the application you are developing. For Linux machines, any programming language that can connect to the X-Window libraries can create Graphical User Interface effects, or gather information about the state of the desktop such as the position of the mouse pointer. Python, a programming language available on most Linux distributions, serves as an simple choice for gathering this information.

Things You'll Need

  • Python Interpreter
Show More

Instructions

    • 1

      Download and install X Libraries from python-xlib.sourceforge.net.

    • 2

      Import libraries into script. Specifically, the "display" module of the W Window System libraries:

      >>>from Xlib import display

    • 3

      Use the display libraries to pull information about the mouse, such as the X and Y coordinates from the system:

      >>>data = display.Display().screen().root.query_pointer()._data
      >>>mouse_x = return data["root_x"]
      >>>mouse_y = data["root_y"]

Related Searches:

References

Comments

Related Ads

Featured