Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion evdev/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ uinput_open(PyObject *self, PyObject *args)
int ret = PyArg_ParseTuple(args, "s", &devnode);
if (!ret) return NULL;

int fd = open(devnode, O_WRONLY | O_NONBLOCK);
int fd = open(devnode, O_RDWR | O_NONBLOCK);
if (fd < 0) {
PyErr_SetString(PyExc_IOError, "could not open uinput device in write mode");
return NULL;
Expand Down
48 changes: 46 additions & 2 deletions evdev/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import stat
import time

from evdev import _uinput
from evdev import _input, _uinput
from evdev import ecodes, util, device

from evdev.events import InputEvent

class UInputError(Exception):
pass
Expand Down Expand Up @@ -121,6 +121,50 @@ def close(self):
_uinput.close(self.fd)
self.fd = -1

def fileno(self):
'''
Return the file descriptor to the open event device. This
makes it possible to pass pass ``InputDevice`` instances
directly to :func:`select.select()` and
:class:`asyncore.file_dispatcher`.'''

return self.fd

def read_one(self):
'''
Read and return a single input event as an instance of
:class:`InputEvent <evdev.events.InputEvent>`.
Return ``None`` if there are no pending input events.
'''

# event -> (sec, usec, type, code, val)
event = _input.device_read(self.fd)

if event:
return InputEvent(*event)

def read_loop(self):
'''Enter an endless ``select()`` loop that yields input events.'''

while True:
r, w, x = select([self.fd], [], [])
for event in self.read():
yield event

def read(self):
'''
Read multiple input events from device. Return a generator object that
yields :class:`InputEvent <evdev.events.InputEvent>` instances. Raises
`BlockingIOError` if there are no available events at the moment.
'''

# events -> [(sec, usec, type, code, val), ...]
events = _input.device_read_many(self.fd)

for i in events:
yield InputEvent(*i)

def write_event(self, event):
'''
Inject an input event into the input subsystem. Events are
Expand Down