sezanzeb / input-remapper

🎮 ⌨ An easy to use tool to change the behaviour of your input devices.
GNU General Public License v3.0
3.75k stars 155 forks source link

could not open uinput device in write mode #29

Closed hannahswain closed 3 years ago

hannahswain commented 3 years ago

Beautiful app, thanks for putting this together!

On trying to apply the keybindings, the app shows "Failed to apply preset":

image

The terminal shows the following:

Applying preset "Nordics" for "OLKB Preonic"
Loaded config from "/home/hannah/.config/key-mapper/config.json"
Stopping injecting keycodes for device "OLKB Preonic"
Loading preset from "/home/hannah/.config/key-mapper/presets/OLKB Preonic/Nordics.json"
Starting injecting the mapping for "OLKB Preonic"
Process Process-5:
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.9/site-packages/keymapper/dev/injector.py", line 431, in _start_injecting
    uinput = evdev.UInput(
  File "/usr/lib/python3.9/site-packages/evdev/uinput.py", line 130, in __init__
    self.fd = _uinput.open(devnode)
OSError: could not open uinput device in write mode
ERROR: Injector was unexpectedly found stopped

I've tried the following:

For background, installed via the AUR. The keyboard is running QMK through the QMK Configurator (so pretty simple configuration), system locale is System Locale: LANG=en_US.UTF-9.

Any idea what could be happening here?

sezanzeb commented 3 years ago

Thanks!

Please post the output of ls -l /dev/uinput and getfacl /dev/uinput

Is the tool running with sudo rights (either via the password prompt that should appear when using the start menu entry or via sudo key-mapper-gtk)? Possibly the uinput devnode has write permissions for the root user missing

sezanzeb commented 3 years ago

closing due to inactivity for now. Feel free to reopen if you have new information ready

heschlie commented 3 years ago

Hi @sezanzeb apologies to resurrect a closed issue but I am seeing this exact error, please let me know if you prefer a new issue. Thanks for developing this tool!

It is prompting me for my sudo password on launch, here is the extra info as well:

$ sudo key-mapper-gtk
key-mapper 0.7.0 1bd32606e9fe552fd171855edbf4854dbd85e690 https://github.com/sezanzeb/key-mapper
python-evdev 1.4.0
Loaded config from "/home/heschlie/.config/key-mapper/config.json"
WARNING: The daemon "key-mapper-service" is not running, mapping keys only works as long as the window is open. Try `sudo systemctl start key-mapper`
Found "Razer Razer DeathAdder Elite", "DuckyChannel International Co., Ltd. Ducky Keyboard", "Razer Razer Tartarus V2"
Loading preset from "/home/heschlie/.config/key-mapper/presets/Razer Razer Tartarus V2/new preset.json"
Applying preset "new preset" for "Razer Razer Tartarus V2"
Loaded config from "/home/heschlie/.config/key-mapper/config.json"
Found "Razer Razer DeathAdder Elite", "DuckyChannel International Co., Ltd. Ducky Keyboard", "Razer Razer Tartarus V2"
Loading preset from "/home/heschlie/.config/key-mapper/presets/Razer Razer Tartarus V2/new preset.json"
Starting injecting the mapping for "Razer Razer Tartarus V2"
Process Injector-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/site-packages/keymapper/injection/injector.py", line 327, in run
    self.context.uinput = evdev.UInput(
  File "/usr/lib/python3.9/site-packages/evdev/uinput.py", line 130, in __init__
    self.fd = _uinput.open(devnode)
OSError: could not open uinput device in write mode
Stopping all injections
Stopping injecting keycodes for device "Razer Razer Tartarus V2"

(key-mapper-gtk:941632): Gtk-CRITICAL **: 08:21:27.992: gtk_main_quit: assertion 'main_loops != NULL' failed
$ ll /dev/uinput 
crw-rw----+ 1 root root 10, 223 Feb 25 12:34 /dev/uinput  
$ getfacl /dev/uinput 
getfacl: Removing leading '/' from absolute path names
# file: dev/uinput
# owner: root
# group: root
user::rw-
user:heschlie:rw-
group::---
mask::rw-
other::---
sezanzeb commented 3 years ago

mine looks similar except for group::rw-, but that shouldn't make a difference.

➜  ~ ll /dev/uinput 
crw-rw----+ 1 root root 10, 223  3. Mär 19:42 /dev/uinput
➜  ~ getfacl /dev/uinput 
getfacl: Removing leading '/' from absolute path names
# file: dev/uinput
# owner: root
# group: root
user::rw-
user:mango:rw-
group::rw-
mask::rw-
other::---

Please run the following:

sudo python3
import evdev
evdev.UInput()

does that work?

sudo evtest should display a row like /dev/input/event16: py-evdev-uinput as long as the python terminal is open

heschlie commented 3 years ago

So I still see the issue:

$ sudo python
Python 3.9.2 (default, Feb 20 2021, 18:40:11) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import evdev
>>> evdev.UInput()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/evdev/uinput.py", line 130, in __init__
    self.fd = _uinput.open(devnode)
OSError: could not open uinput device in write mode
>>> 

Tried updating the FACL to reflect yours but am still seeing the issue, going to investigate evdev some more, it seems like this isn't an error in your application but something in my setup.

heschlie commented 3 years ago

OK I think I've sorted it, leaving this for others, and likely my future self.

You need to install xf86-input-evdev on arch, not sure if other distros include an equivalent by default, but after installing everything is working!

sezanzeb commented 3 years ago

"X.org evdev input driver" strange, evdev is part of the kernel and should be sitting below X, so this package should not be the reason why it didn't work.

That package depends on mtdev and libevdev (see https://archlinux.org/packages/extra/x86_64/xf86-input-evdev/). Were those two installed before you installed xf84-input-evdev?

heschlie commented 3 years ago

They look to have been installed some time back :shrug:

$ paclog --package=mtdev
[2019-07-13 16:49] [ALPM] installed mtdev (1.1.5-2)
...
$ paclog --package=libevdev
[2019-07-13 16:49] [ALPM] installed libevdev (1.7.0-1)
...

I don't claim to be an expert on this side of Linux, but perhaps there needed to be some userspace translation to connect the dots?

sezanzeb commented 3 years ago

https://stackoverflow.com/a/48641401

Maybe the uinput driver module - as mentioned in that stack overflow answer - wasn't loaded until that package was installed?

Since it works for you now I'm closing it again

sezanzeb commented 2 years ago

I had this problem today, installing xf86-input-evdev didn't help and modprobe uinput couldn't find uinput module. This was probably caused by package/kernel upgrades, rebooting the system fixed the issue for me.

kangtyou commented 2 years ago

I had this problem today, installing xf86-input-evdev didn't help and modprobe uinput couldn't find uinput module. This was probably caused by package upgrades, rebooting the system fixed the issue for me.

This work for me, just reboot

ShinyZero0 commented 1 year ago

Is there a solution? I have the same issue with xkeysnail, another python remapping tool. I use void linux and have xf86-input-evdev installed. My user is in input group, but program works only with sudo. It ran well without sudo on Fedora just yesterday (i distro-hopped)