4

I am trying to use evdev to simulate touch input.

from evdev import UInput, AbsInfo, ecodes as e

cap = {
    e.EV_KEY : [e.KEY_A, e.KEY_B],
    e.EV_ABS : [
        (e.ABS_X, AbsInfo(value=0, min=0, max=255,
                          fuzz=0, flat=0, resolution=0)),
        (e.ABS_Y, AbsInfo(0, 0, 255, 0, 0, 0)),
        (e.ABS_MT_POSITION_X, (0, 255, 128, 0)) ]
}

ui = UInput(cap, name='example-device', version=0x3)

Adding myself to the input group, the error is:

Traceback (most recent call last):
  File "mouse.py", line 12, in <module>
    ui = UInput(cap, name='example-device', version=0x3)
  File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 125, in __init__
    self._verify()
  File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 221, in _verify
    raise UInputError(msg.format(self.devnode))
evdev.uinput.UInputError: "/dev/uinput" cannot be opened for writing

After running chmod +0666 /dev/uinput the error changes to:

Traceback (most recent call last):
  File "mouse.py", line 12, in <module>
    ui = UInput(cap, name='example-device', version=0x3)
  File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 147, in __init__
    _uinput.create(self.fd, name, vendor, product, version, bustype, absinfo)
SystemError: /builddir/build/BUILD/Python-3.6.2/Objects/longobject.c:404: bad argument to internal function

Removing (e.ABS_MT_POSITION_X, (0, 255, 128, 0)):

Traceback (most recent call last):
  File "mouse.py", line 12, in <module>
    print(ui)
  File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 171, in __str__
    evtypes = [i[0] for i in self.capabilities(True).keys()]
  File "/home/user/.virtualenvs/venv/lib/python3.6/site-packages/evdev/uinput.py", line 200, in capabilities
    raise UInputError('input device not opened - cannot read capabilites')
evdev.uinput.UInputError: input device not opened - cannot read capabilites
ovg
  • 1,486
  • 1
  • 18
  • 30

0 Answers0