RetroPie-Setup/scriptmodules/admin/joy2key
cmitu d417e06978 joy2key: use 'uinput' for emitting keyboard events
Recent Linux kernels (6.2+) have the ability to disable the 'TIOCSTI' ioctl, thus rendering unusable the method of sending keyboard events to the controlling terminal via `fcntl.ioctl` [1]. Not all distributions have left it enabled currently, but Ubuntu 24.04 has it enabled, affecting the `runcommand` ability to generate keyboard events for a joystick.

Use the `python-uinput` module to create a virtual keyboard and send the proper events through it, without relying on the 'curses' or 'fcntl' modules. Now, since the new module doesn't know about Termios codes, which were used previously, I've added a translation table to accomodate scripts using those capability codes. The `python-uinput` uses the Linux event codes [2].

The new method needs the `uinput` Linux kernel module to be loaded beforehand - so add the module to be automatically loaded. The user also needs to be part of the 'input' group, otherwise they won't be able to use the `uinput` interface -  RetroPie doesn't automate that, but assumes the installation user belongs to that group.

We also don't need the `termios`/`fnctl` calls, so the terminal handling part has been removed, simpplifying a bit the code.

OTHER changes:
 - the device path (/dev/jsX) is now ignored. It hasn't been working since the switch to SDL2 for input processing, but was still parsed for compatibility with the old version.
 - when invoking with the debug (--debug|-d) parameter, the script now runs in the foreground, instead of forking and running in the background. It's easier when running it to diagnose issues; running with debugging enabled should not be used for regular usage.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83efeeeb3d04b22aaed1df99bc70a48fe9d22c4d
[2] https://github.com/tuomasjjrasanen/python-uinput/blob/master/src/ev.py
2024-10-12 06:52:59 +01:00
..
joy2key.py joy2key - split out into standalone module and rework helper code 2021-08-04 00:03:32 +01:00
joy2key_sdl.py joy2key: use 'uinput' for emitting keyboard events 2024-10-12 06:52:59 +01:00
osk.py joy2key: teach the OSK to start with a value 2023-02-25 18:23:22 +00:00