moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

on_release event is not fired when a key is pressed in keyboard Listener [Ubuntu] #397

Closed hash3liZer closed 3 years ago

hash3liZer commented 3 years ago

Description I am currently on Ubuntu. Previously, i have done this on Windows and it worked all fine. But on linux the callback simple isn't called when a key is pressed.

Platform and pynput version Worked Fine on: Ubuntu: 21.04 Pynput: 1.7.3

To Reproduce The following code is enough to reproduce the bug. It would fine under Windows. But on linux it doesn't fire the on_release function:

from pynput import keyboard

def toprint(key):
    print(str(key))

with keyboard.Listener(
    on_release = toprint 
) as listener:
    listener.join()
moses-palmer commented 3 years ago

Thank you for your report.

Please see the platform limitations for Linux.

To summarise: keyboard listeners on Linux use either X or uinput as backend. Ubuntu 21.04 switched to using Wayland instead of X as display and input server, and the security model of this system is incompatible with input monitors. There exist drafts for protocols adding this support, but as far as I know, none have been accepted by all vendors.

uinput is still an option, but it comes with additional restrictions.