Questions tagged [pynput]

pynput is a Python library for controlling and monitoring input devices.

From pynput's Python Package Index page:

This library allows you to control and monitor input devices.
Currently [as of late 2018], mouse and keyboard input and monitoring are supported.

659 questions
3
votes
1 answer

How to manage two threads, pynput mouse listener and while loop?

I have a mouse listener: from pynput.mouse import Listener, Button def on_click(x, y, button): if button == Button.left: xy_dict["x"] = x xy_dict["y"] = y if button == Button.right: raise MyException(button) with…
bswan
  • 57
  • 5
3
votes
2 answers

Trying to create a mouse recorder, but it keeps looping endlessly?

I'm trying my hand at Pynput, and I'm starting off with creating a simple program to record the movements of a mouse, and then replay those movements once a button is clicked. However, every time I click the mouse, it just starts to freak out and…
Zhade
  • 33
  • 4
3
votes
1 answer

How to fix "AttributeError(name) from None" when trying to use "Button.Left" in pynput

I am using pynput and am trying to get the mouse to click, for which I import from pynput: from pynput.mouse import Button, Controller Then in line 8, I do this: button = Button.Left And as a result, I get this error: Traceback (most recent call…
JMP
  • 43
  • 1
  • 2
  • 4
3
votes
2 answers

Python pynput - program lags upon start

So I've been trying to make a simple program that, upon clicking the right mouse button, makes my mouse click the left button 3 times in 0.5 second intervals. However, when I start the program and do right click, the program does what it's told to…
3
votes
1 answer

Comparing a KeyCode object to string in python

I'm trying to trigger functions on key presses in python. I'm using the pynput library's listen function, which returns a Keycode object. I've tried casting the object to string but the following code still returns the following output (when…
Alex Dube
  • 45
  • 1
  • 5
3
votes
1 answer

how to wait until a hotkey is pressed in python3 without the terminal window needing to be up?

I would like some sort of blockade that waits until a certain hotkey is pressed. I would be happy with something like input('Press Enter to continue') except for the fact that that would require my screen be on the terminal page, I would like this…
christina li
  • 83
  • 1
  • 5
3
votes
4 answers

key.char gives AttributeError when using Key.f5 in Python Pynput

Im trying to make a very simple program that presses the F5 key when I press another key (example q). Whenever I use regular characters a-z I compare using if key.char == 'q': This works fine until I introduce Key.f5 (or any other Key.) if key.char…
LasseAarhus
  • 79
  • 1
  • 12
3
votes
1 answer

type(list[0]) returns pynput.keyboard._win32.KeyCode

My problem is how pynput returns the data (I hope that's how you would say it?). So what I'm trying to do is have the listener record keyboard input, then use what letters are added to the list to make a string in word. Although, it seems like the…
Duck Wizard
  • 61
  • 1
  • 8
3
votes
1 answer

Testing python stdout on input prompt

The test for the following method checks that the stdout in prompt is correct. When 'input()' gets called it waits for the user to press enter and interrupt. The test is passing by auto keypress-ing 'enter'. This is hacky and there must be a better…
Huasmc
  • 63
  • 1
  • 6
3
votes
1 answer

How to stop a program when a key is pressed in python?

I have a program that is an endless loop that prints "program running" every 5 seconds and I want to stop it when I press the end key. So I created a key listener that returns false if the end key is pressed. That should work if I won't have the…
Doron Sever
  • 65
  • 2
  • 2
  • 9
2
votes
1 answer

Listen for keyboard shortcut ESC + ESC then run some code

I want to listen for the keyboard shortcut ESC + ESC and then run some code. What I mean is that, if the user presses the ESC key twice, then some code should get executed. I tried the following code, but it doesn't work: from pynput import…
Hector
  • 65
  • 8
2
votes
1 answer

Pynput difference between listener.join and listener.start

I have the following 2 extracts of starting pynput's keyboard listener. Source # Collect events until released with keyboard.Listener( on_press=on_press, on_release=on_release) as listener: listener.join() # ...or, in a…
2
votes
1 answer

problem running pynput module in google colab

I am trying to install and import the pynput module using google colab. However, although I managed to install using "!pip install pynput", when I import the module such as: from pynput.keyboard import Key, Listener I get the below…
2
votes
0 answers

How do I use Python input while using pynput as well? Python input not waiting for user input

I am using pynput primarily because there are cases when I don't want the user to have to press enter after supplying an input e.g. when using arrow keys to navigate a CLI. There are cases where I want to use Python's input function to extract a…
2
votes
1 answer

"Input event monitoring will not be possible until it is added to accessibility clients." during crontab

I created a Python script with pynput which I want to run with a crontab. The script needs access to input monitoring. In "Security & Privacy" I added the Python version which I use in my crontab. I copied the path from my crontab into the Finder Go…
teres
  • 53
  • 6
1 2
3
43 44