Set mouse absolute coordinates

Asked by Kaar3l

import time

import uinput

def main():
    events = (
        uinput.REL_X,
        uinput.ABS_X,
        uinput.BTN_LEFT,
        uinput.BTN_RIGHT,
        )

    device = uinput.Device(events)

    for i in range(20):
        # syn=False to emit an "atomic" (5, 5) event.
        device.emit(uinput.ABS_X, 1022)

        # Just for demonstration purposes: shows the motion. In real
        # application, this is of course unnecessary.
        time.sleep(0.01)

if __name__ == "__main__":
    main()
I tested that exaple script with abs coords, but that doesn't put my mouse to the position where it should. :( How could I use the absolute coordinates to set my mouse location.

Question information

Language:
English Edit question
Status:
Solved
For:
python-uinput Edit question
Assignee:
No assignee Edit question
Solved by:
Kaar3l
Solved:
Last query:
Last reply:
Revision history for this message
a (tuomasjjrasanen) said :
#1

Hi and thanks for your question!

The behavior you describe is expected. Xorg does not assign mouse handlers for absolute axis devices by default. If you want to move mouse cursor with your device, you should change asbolute axis to relative axis. See examples/mouse.py for an example.

Python-uinput provides just tools for creating arbitarary input devices. Then it's up to upper layers (windowing system for example) to decide what to do with those devices. However, if you want map absolute axis to mouse movement, it's still possible but I guess you need to google for a proper solution.

Possible google keywords: Xorg input absolute axis joystick move mouse cursor

Revision history for this message
Kaar3l (kaar3l) said :
#2

Thanks for your reply!

I solved it by using Xlib and your python-uinput.
Xlib example:

# 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
import time

def mousepos():
    """mousepos() --> (x, y) get the mouse coordinates on the screen (linux, Xlib)."""
    data2 = display.Display().screen().root.query_pointer()._data
    return data2["root_x"], data2["root_y"]

if __name__ == "__main__":

    for i in range(1, 50):

        pos=mousepos()
        print pos[0]
        print pos[1]
        time.sleep (1)