tuomasjjrasanen / python-uinput

Pythonic API to Linux uinput module
http://tjjr.fi/sw/python-uinput/
GNU General Public License v3.0
289 stars 71 forks source link

how to make ABS_X and ABS_Y attributes work with mouse pointer movement #43

Open VictorGimenez opened 1 year ago

VictorGimenez commented 1 year ago

I would like to make the mouse pointer/cursor move independently and directly to the given x and y positions without the need to use the relative attributes (REL_X, REL_Y) seen that these two ones make the mouse movement using as reference the actual x and y positions. I wrote this script below to try make the mouse pointer goes directly but nothing happens.

import uinput
from time import sleep

def createDevice():
    device = uinput.Device([
        uinput.ABS_X,
        uinput.ABS_Y,
        uinput.BTN_LEFT,
        uinput.BTN_RIGHT,
        ])
    return device

def emitActions(device):
    sleep(1)
    device.emit(uinput.ABS_X, 26, syn=False)
    sleep(1)
    device.emit(uinput.ABS_Y, 665, syn=False)
    sleep(1)
    device.syn()
    sleep(1)
    device.emit(uinput.BTN_LEFT, 1)
    sleep(1)
    device.emit(uinput.BTN_LEFT, 0)

def main():
    dev = createDevice()
    emitActions(dev)

if __name__ == "__main__":
    main()

When I debugged this code I didn't get errors, but I would like to know what's missing there in this code to make that the mouse pointer goes to the desired x and y positions?

VictorGimenez commented 1 year ago

Any tips?

trycoon commented 1 year ago

I'm asking the same question, did you find an answer? Is it possible to get the pointers current position using Python? If so, then we could add/substract current position to goal position and send that as REL_X and REL_Y, right?