4

我正在尝试使用 evdev 来模拟触摸输入。

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)

将自己添加到input组中,错误是:

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

运行后chmod +0666 /dev/uinput错误变为:

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

删除(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
4

0 回答 0