pynput icon indicating copy to clipboard operation
pynput copied to clipboard

pynput keyboard listener doesnt work on wayland (even with uinput)

Open Mitutoyum opened this issue 11 months ago • 6 comments

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

Mitutoyum avatar Feb 15 '25 07:02 Mitutoyum

Bummer. So much for my moonshot hope that it might run under WSL 2 :)

feoh avatar Mar 05 '25 22:03 feoh

Same issue for me. I'm running Arch w/ Gnome & Wayland.

bendavis78 avatar Apr 26 '25 15:04 bendavis78

no solution for this?

Mitutoyum avatar May 02 '25 11:05 Mitutoyum

@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.

moses-palmer avatar May 06 '25 17:05 moses-palmer

@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?

lianghongzhuo avatar Oct 30 '25 15:10 lianghongzhuo

Could it be a KDE issue?

I can confirm that it does not work in KDE but does work in GNOME for me

Hedwig7s avatar Nov 08 '25 12:11 Hedwig7s