gvalkov/python-evdev

Mouse injection not working

TruthSeeker-3e8 opened this issue · 1 comments

I was working on program for controlling computer over LAN, but when I tried to add mouse control. Nothing seemed to happen. Keyboard works fine, but mouse seems to be completely ignored. Originally tested on Hyprland, but to be sure Hyprland is not to blame I tested it on GNOME as well., but no luck there either. I got no crash and no errors, even tried to use Try Except if it catches any exception, but nothing.

OS: ArcoLinux x86_64
Kernel: 6. 8. 7-arch1-1
Compositor: Wayland
Gnome version: 46
Hyprland: hyprland-git 0.39.1.r4.82222342-1

I created simplified code example which contains the main problematic parts along with keyboard test to prove it works for keyboard.

Code:

#!venv/bin/python

import time
import os

class trigg_unix:
    global ui
    global e
    def move_cursor(sx,sy):
        print("Moving:[{x},{y}]".format(x=sx,y=sy))
        ui.write(e.EV_REL, e.REL_X,sx)
        ui.write(e.EV_REL, e.REL_Y,sy)
        ui.syn()
    def press_uparrow():
        print("Pressing arrow up")
        ui.write(e.EV_KEY,e.KEY_UP,1)
        ui.write(e.EV_KEY,e.KEY_UP,0)
        ui.syn()

def init_unix():
    global trigg
    global ui
    global e
    from evdev import UInput,AbsInfo, categorize, ecodes as e
    cap = {e.EV_REL: [e.REL_X, e.REL_Y],e.EV_KEY: [e.KEY_UP,e.KEY_DOWN,e.KEY_RIGHT,e.KEY_LEFT,e.KEY_ENTER,e.KEY_TAB, e.KEY_ESC,e.KEY_VOLUMEUP,e.KEY_VOLUMEDOWN],}
    ui = UInput(cap,"virtual-device")
    print("Unix loaded")
    trigg=trigg_unix
    return ui

def mouse_test():
    print("Testing mouse control move by [1000,1000]:")
    for t in range(1,5):
        time.sleep(1)
        print("Testing in {tl}".format(tl=5-t))
    trigg_unix.move_cursor(1000,1000)

def keyboard_test():
    print("Testing keyboard by pressing arrow up")
    for t in range(1,5):
        time.sleep(1)
        print("Testing in {tl}".format(tl=5-t))
    trigg_unix.press_uparrow()


def main():
    print("Creating device:")
    print(init_unix())
    for t in range(1,5):
        time.sleep(1)
        print("Clearing log in {tl}".format(tl=5-t))
    keyboard_test()
    time.sleep(3)
    os.system("clear")
    mouse_test()

if __name__ == "__main__":
    main()

Found the solution it seems that left mouse button must included in the devices capabilities, well I haven't expected it.