I'm trying to get pynput working on linux (ubuntu) but I just can't get it to work. I'm running my script on a terminal window on the desktop.
I've installed pynput but just it just won't detect my keystrokes. Here's the code that I'm using from my main script:
from pynput.keyboard import Key, Listener, Controller
from pynput import keyboard
def on_press():
print("key detected: " + str(key.char)))
listener = keyboard.Listener(on_press=on_press)
listener.start()
I've tried:
"sudo pip3 install web3"
"sudo pip3 install pynput"
"sudo pip3 install xlib"
"DISPLAY=:0.0 python3 -c 'import pynput'"
"xhost +"
And executing my script:
But none of that seems to work regardless of running as root or not.
I do however get Xlib.xauth: warning, no xauthority details available
, idk if that's causing the issue?
Any advice is appreciated. Cheers.
Maybe
pip install pynput none
or you can use --user
,and install the files into your home directory to fix this. So, try executing the command
pip install pynput user
I encounted similiar problem, and found this link useful. "No protocol specified" when running a sudo/su app on Ubuntu Linux
Newer systems by design don't allow graphical applications as root (it's a Wayland thing). Workaround:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.