pynput keyboard listener doesnt work on wayland (even with uinput)
Description pynput keyboard listener doesnt work on wayland (even with uinput) i have tried running with root, reinstalling the package, manually enabling uinput, nothing worked i had to switch back to x11 as a temporary solution
it used to work before.
Platform and pynput version OS: Arch Linux x86_64 Kernel: Linux 6.13.2-arch1-1 DE: KDE Plasma 6.3.0 WM: KWin (Wayland) python version: 3.13.1 (venv) pynput version: 1.7.7
Bummer. So much for my moonshot hope that it might run under WSL 2 :)
Same issue for me. I'm running Arch w/ Gnome & Wayland.
no solution for this?
@Mitutoyum, I also run on a Wayland system (Ubuntu 25.04) and unfortunately cannot reproduce your problem. Could it be a KDE issue? I tested with the following script:
from pynput import keyboard
def on_press(key, injected):
try:
print('alphanumeric key {} pressed ({})'.format(
key.char, injected))
except AttributeError:
print('special key {} pressed ({})'.format(
key, injected))
def on_release(key, injected):
print('{0} released'.format(
key))
if key == keyboard.Key.esc:
# Stop listener
return False
def on_click(x, y, button, pressed):
if pressed:
print('Pressed {} at ({}, {})'.format(button, x, y))
# Collect events until released
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
Make sure to run it with PYNPUT_BACKEND_KEYBOARD=uinput, and ensure you are root.
@Mitutoyum, I also run on a Wayland system (Ubuntu 25.04) and unfortunately cannot reproduce your problem. Could it be a KDE issue? I tested with the following script:
from pynput import keyboard
def on_press(key, injected): try: print('alphanumeric key {} pressed ({})'.format( key.char, injected)) except AttributeError: print('special key {} pressed ({})'.format( key, injected))
def on_release(key, injected): print('{0} released'.format( key)) if key == keyboard.Key.esc: # Stop listener return False
def on_click(x, y, button, pressed): if pressed: print('Pressed {} at ({}, {})'.format(button, x, y))
Collect events until released
with keyboard.Listener( on_press=on_press, on_release=on_release) as listener: listener.join() Make sure to run it with
PYNPUT_BACKEND_KEYBOARD=uinput, and ensure you are root.
Is it possible to run without root or sudo?
Could it be a KDE issue?
I can confirm that it does not work in KDE but does work in GNOME for me