This snippet defines a function mousepos()
which gets the mouse position on the screen. The package python-xlib is required.
Get the mouse position on the screen on Linux.
# mousepos.py (linux only)
"""module mousepos
"""
# uses the package python-xlib
# from http://snipplr.com/view/19188/mouseposition-on-linux-via-xlib/
from Xlib import display
def mousepos():
"""mousepos() --> (x, y) get the mouse coordinates on the screen (linux, Xlib)."""
data = display.Display().screen().root.query_pointer()._data
return data["root_x"], data["root_y"]
if __name__ == "__main__":
print("The mouse position on the screen is {0}".format(mousepos()))
Gribouillis
1,391
Programming Explorer
Team Colleague
Gribouillis
1,391
Programming Explorer
Team Colleague
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Gribouillis
1,391
Programming Explorer
Team Colleague
Gribouillis
1,391
Programming Explorer
Team Colleague
Gribouillis
1,391
Programming Explorer
Team Colleague
woooee
814
Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.