moses-palmer / pynput

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

Lib does not work in focused terminal #551

Closed Cvaniak closed 1 year ago

Cvaniak commented 1 year ago

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

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

moses-palmer commented 1 year ago

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.

Cvaniak commented 1 year ago

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.