Ask coding questions

← Back to all posts
How do I get pynput to work?
TurtleAndrew

Please tell me why it gives me an error message every time I run it. Also, I tried both python 2 and 3. I also tried to download Xlib and import it to fix the problem along with even trying to make a display. It didn't work. Heres the error message it gave me:

Voters
Lucas_Williams
TurtleAndrew
Comments
hotnewtop
[deleted]

Try this:

TurtleAndrew

Works great, thanks!

Hariveera

its work try this
import os
os.system("pip install pynput")
then type for mouse
from pynput.mouse import Button, Controller
mouse = Controller()

TurtleAndrew

@Hariveera Thanks! I don't really need it any more but it might come in handy some time.

AnthonyFerr

I had to pip install xlib then pip3 install pynput for it to work, and I wasn't even using replit. It's doubtful that a browser environment will ever be able to use this module.

TurtleAndrew

@AnthonyFerr I think so to. But still, there could be a way but I'm doubtful there is.

Nettakrim

i think its due to not having a screen try useing pygame not python

TurtleAndrew

@Nettakrim can pygame press keys?

Hariveera

for keyboard
from pynput.keyboard import Key, Controller
keyboard = Controller()

albertlu2

Lucas_Williams

I have the same question. ^^

TurtleAndrew

@Lucas_Williams IDK but I do think using the pygame language will work.

Lucas_Williams
TurtleAndrew

@Lucas_Williams In that case, it might just not work on repl. If you tell me what your trying to do with it, I might be able to tell you a different way to do it or a different package to use.

Lucas_Williams

@TurtleAndrew I’m trying to have a program force me to type letters. So I start it type in a letter and a number and wherever my cursor is it types that character however many times I set it to. I tried it on python on my PC and i can get it to work was just hoping it would work on repl as well.

TurtleAndrew

@Lucas_Williams Ok, I just don't think pynput will work on repl.