moses-palmer/pynput

Lib does not work in focused terminal

Closed this issue · 2 comments

Description

When I run Monitor Keyboard or any other code with pynput it does not work in main workspace. It does register all events when I move to another.
How ever it also sometimes register events when I unfocus terminal to another app (but it needs to be another app than terminal) in the same workspace.

Platform and pynput version

  • Tested on fresh install of Manjaro (up to this date) with Gnome
  • Pynput versions 1.7.6 and 1.6.0 and 1.5.2 (tested just few)
  • Python versions 3.10.10, 3.10.8, 3.9.16, 3.9.4, 3.7.6 (just few random, including ones that works on long running manjaro)

To Reproduce

I had problem after fresh Manjaro install. First it was from old image on USB then upgraded to newest version. I tested on non-upgraded from USB and the same problem appeared. Same for fresh downloaded Manjaro today.
After OS install (or booting from USB) I install pip and then create venv python3 -m venv venv and install pynput with that I run example with Monitoring Keyboard.

Other

  • I also tested keyboard, blessed, urwid and it works fine
  • I tried to run with sudo or another user
  • I changed python versions and way of installing it
  • I tried using built in terminal, terminator, wezterm
  • I checked with external keyboards
  • I checked to listen Mouse events instead of Keyboard

Thank you for your report.

Do you by any chance run a Wayland session? When doing so, applications running under Xwayland work, but not applications running under pure Wayland.

Hi!
Thank you for quick response.
I have seen Wayland word multiple times looking for solutions, but I was almost sure that it is not my case (but I did not know what it is and from context I thought it is another distro).
After more research I found that this problem was already mentioned #189 .
As then for future users: Manjaro and Ubuntu in some cases switched from X11 to Wayland. You can check if you are running Wayland by:

echo $XDG_SESSION_TYPE

And if it says wayland it means that you can encounter problem like in linked issue.

Solution1

Best solution so far I found is to start new terminal session like:

export WAYLAND_DISPLAY=unset
# run you emulator
terminator # In this window pynput should work
# to finalize 
unset WAYLAND_DISPLAY

Solution2

You can also install xterm and running app via this window.