Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
---------

Unreleased
==========

- Allow ``UInput`` event types without event codes, such as ``EV_REP``.


1.9.3 (Feb 05, 2025)
====================

Expand Down
22 changes: 22 additions & 0 deletions src/evdev/uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,25 @@ uinput_write(PyObject *self, PyObject *args)
}


static PyObject *
uinput_enable_event_type(PyObject *self, PyObject *args)
{
int fd;
uint16_t type;

int ret = PyArg_ParseTuple(args, "ih", &fd, &type);
if (!ret) return NULL;

if (ioctl(fd, UI_SET_EVBIT, type) < 0) {
_uinput_close(fd);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

Py_RETURN_NONE;
}


static PyObject *
uinput_enable_event(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -376,6 +395,9 @@ static PyMethodDef MethodTable[] = {
{ "enable", uinput_enable_event, METH_VARARGS,
"Enable a type of event."},

{ "enable_type", uinput_enable_event_type, METH_VARARGS,
"Enable an event type without enabling an event code."},

{ "set_phys", uinput_set_phys, METH_VARARGS,
"Set physical path"},

Expand Down
8 changes: 7 additions & 1 deletion src/evdev/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def __init__(
events : dict
Dictionary of event types mapping to lists of event codes. The
event types and codes that the uinput device will be able to
inject - defaults to all key codes.
inject - defaults to all key codes. An event type mapped to an
empty sequence enables the event type without enabling any event
codes, which is useful for types such as ``EV_REP``.

name
The name of the input device.
Expand Down Expand Up @@ -165,6 +167,10 @@ def __init__(
for prop in input_props:
_uinput.set_prop(self.fd, prop)

for etype, codes in events.items():
if not codes:
_uinput.enable_type(self.fd, etype)

for etype, code in prepared_events:
_uinput.enable(self.fd, etype, code)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def test_enable_events(c):
assert sorted(cap[e.EV_KEY]) == sorted(c["events"][e.EV_KEY])


def test_enable_event_type_without_codes(c):
e = ecodes
c["events"] = {e.EV_KEY: [e.KEY_A], e.EV_REP: []}

with uinput.UInput(**c) as ui:
repeat = ui.device.repeat
assert repeat.delay > 0
assert repeat.repeat > 0


def test_abs_values(c):
e = ecodes
c = {
Expand Down