Skip to content
Sign upLog in
← Back to Community

Why can't I use keyboard module?

Profile icon
Fire-Wizard

I wanted to make some hotkeys. so I found out about keyboard and it's useful feature that detects keypress which I really wanted.
Then I tried importing it, first it took A LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG TIME to load!
And then it said an error message

Voters
Profile icon
AndrewLoconte
Profile icon
DimitriLJ
Profile icon
55Shubhojyoti
Profile icon
TobyWalter
Profile icon
LajosN
Profile icon
OwenGillming
Profile icon
thomas6626
Profile icon
MemeManHimself
Profile icon
M07
Profile icon
Alex0204
Comments
hotnewtop
Profile icon
JBloves27

Oh, well, because it is python, you might want to use the getch module or maybe as Wumi4 said, use pynput?

Profile icon
Wumi4

Hi! Can you please show us the error?

The problem with the keyboard module is always a never-solved problem with Repl. Seriously, try it on your local machine is a much better choice.

Profile icon
Fire-Wizard

@Wumi4
okay, is there a alternative
that can help me detect a key-press?

Profile icon
Wumi4

@Aayan11
I have found one. It's called pynput. You can search it for more info.

Profile icon
Fire-Wizard

it shows me this error..."
Traceback (most recent call last):
File "main.py", line 1, in
import pynput
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pynput/init.py", line 40, in
from . import keyboard
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pynput/keyboard/init.py", line 31, in
backend = backend(name)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pynput/_util/init.py", line 76, in backend
raise ImportError('this platform is not supported: {}'.format(
ImportError: this platform is not supported: ("failed to acquire X connection: No module named 'Xlib'", ModuleNotFoundError("No module named 'Xlib'"))

Try one of the following resolutions:

  • Please make sure that you have an X server running, and that the DISPLAY environment variable is set correctly"
Profile icon
M07

What language? (I'm not very skilled don't judge)

Profile icon
Fire-Wizard

@M07
oh sorry I forgot to mention, it is python

Profile icon
M07

@Aayan11
Ok, I'm kinda good with python, but I'm nowhere near skilled enough to be able to do that kind of thing, if I could help I would love to, but I worry I would just be a hindrance.

Profile icon
Fire-Wizard

@M07
nah at this point anything will help

Profile icon
TobyWalter

Getch comes up with an error when I try to import it, it may also not be compatible.

Profile icon
YPD

You need root to use the keyboard module... and that's a thing you can't do on repl.it. You can't be root.

Profile icon
InvisibleOne

I don't think replit supports it, I would look into getch