Skip to content

Switch to pynput#342

Draft
Yanis002 wants to merge 5 commits intoToufool:mainfrom
Yanis002:keyboard_removal
Draft

Switch to pynput#342
Yanis002 wants to merge 5 commits intoToufool:mainfrom
Yanis002:keyboard_removal

Conversation

@Yanis002
Copy link

@Yanis002 Yanis002 commented Feb 24, 2026

This PR makes the necessary changes to transition from keyboard to pynput, the reason for that is recent Linux updates completely broke dumpkeys, which keyboard is using under the hood, so basically this became unusable for me unfortunately

Summary of the changes:

  • updated the hotkey tab in the settings UI to use QKeySequenceEdit instead of a QLineEdit
  • added an eventFilter override in __SettingsWidget to filter out escape and enter keys (to keep a consistent behavior with how it works with keyboard), this can also allow one to filter more keys easily so I think it's a nice addition
  • created a QThread specifically for handling hotkeys, this is the place that use pynput, this allowed me to do cool clean-up stuff
  • simplified a lot of hotkeys.py:
    • send_command now simply relies on HotKeyThread to figure out which action to perform
    • actions are set when the thread initializes, before it was setting them each time you'd set an hotkey, I thought it wasn't very efficient but maybe there's a good reason behind it that I missed
    • set_hotkey was simplified a lot thanks to the dedicated thread, which handles everything keyboard-related basically
  • removed pyautogui as I realised the only reason why it was used was to work around issues with keyboard

I chose to keep the current format when reading/saving settings, I didn't want to break anything for end-users but the drawback I have currently is I had to create a dictionnary of the keys as strings to convert them to the pynput types

Things left to test/make sure of (among the things that I thought of at least):

  • Windows testing, I'll admit it I didn't do any since I moved to Linux since last year, in theory it works, I just never had the opportunity to confirm it
  • numpad keys vs the regular number keys (5 vs numpad 5 for instance)
  • home and numpad home keys (but I have no idea which kind of keyboard has a secondary home key, that one confuses me a bit)
  • behavior of numpad "action" keys like delete vs the del/suppr key
  • behavior of numpad "action" keys vs numpad number keys
  • make sure the "action" keys don't trigger both type of number keys
  • all known keys as a key sequence if possible, I think I handled most of them but I'm concerned that I missed stuff on this

Side note: the pynput docs says this should be Wayland-ready but the pyproject.toml/uv.lock stuff didn't add anything about python-uinput (which the Wayland compat stuff relies on), ironically this library uses dumpkeys too lol (but afaik Wayland isn't officially supported so 🤷 ), oh also still according to the docs Xwayland can only receive keys but not send them, that can be an issue but I think it can be worked around with the auto-controlled mode

I'm wide open to suggestions on this of course, I'm far from being a pynput expert and even a python one 🙏 (also this is a draft PR only because it's not ready to merge yet because of what I mentioned above about the things to test/make sure of)


I'm gonna read the contributing guidelines and address any necessary change soon

@Yanis002
Copy link
Author

Yanis002 commented Feb 24, 2026

I just realised I forgot to add something to terminate the thread properly when closing the program even though I told to myself 50 times not to forget about it lol, will do soon!

Comment on lines 29 to 39
<!-- Keep in sync with scripts/install.ps1 and src/error_messages.py -->
```shell
sudo usermod -a -G tty,input $USER
sudo touch /dev/uinput
sudo chmod +0666 /dev/uinput
echo 'KERNEL=="uinput", TAG+="uaccess"' | sudo tee /etc/udev/rules.d/50-uinput.rules
echo 'SUBSYSTEM=="input", MODE="0666" GROUP="plugdev"' | sudo tee /etc/udev/rules.d/12-input.rules
echo 'SUBSYSTEM=="misc", MODE="0666" GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/12-input.rules
echo 'SUBSYSTEM=="tty", MODE="0666" GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/12-input.rules
loginctl terminate-user $USER
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are part of the keyboard group workaround and can be deleted if not needed with pynput anymore.

As the comment alludes to, same with scripts/install.ps1 and src/error_messages.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants