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
13
votes
9 answers

How to fix Error "No module named 'pynput'"? even after downloading with pip?

I downloaded the pynput in my windows with pip following the video: https://youtu.be/DTnz8wA6wpw with cmd in administrator mode pip install pynput and when i run the code, the pycharm and spyder3 show the error: Traceback (most recent call…
Nilson Rodrigues
  • 149
  • 1
  • 1
  • 3
9
votes
1 answer

plot mouse movement Python

I would like to plot the movement of the mouse in near real-time using matplotlib and pynput, but I suspect I am getting some issues with the code being blocked. Code is uses a simplified version of this answer. import matplotlib.pyplot as plt from…
M.T
  • 4,917
  • 4
  • 33
  • 52
8
votes
2 answers

Getting error when using pynput with pyinstaller

A friend of mine asked me to write him a program, and I used pynput to handle some of the inputs and other features. When I convert the program an executable with pyinstaller, launcing the executable gives me this error: File…
user13140483
5
votes
0 answers

Can pynput handle input from a specific keyboard only? If yes, how can this be achieved?

If several physical keyboards are connected to a system, or a single physical keyboard is connected but a touch screen is also used in the same time, can pynput be configured to filter the input by device, or I should go one level down and use…
Alex M.M.
  • 501
  • 1
  • 7
  • 18
5
votes
3 answers

How to simulate a mouse click while holding the SHIFT key in Windows?

Hello I'm trying to simulate a mouse click while holding the SHIFT key. I have been trying to do this with the pynput module. This is my code so far: from pynput.keyboard import Key from pynput.keyboard import Controller as Cont from pynput.mouse…
teller.py3
  • 822
  • 8
  • 22
5
votes
2 answers

(pynput) capture keys prevent sending them to other applications

Well on pynput I capture a key (say spacebar) by doing something alike: from pynput import keyboard from pynput.keyboard import Key def on_press(key, ctrl): if key == Key.space: print('captured') def main(): with…
paul23
  • 8,799
  • 12
  • 66
  • 149
4
votes
2 answers

Retrieving x and y mouse positions for click and release in Pynput

I am using Python 3.9.7 with pynput, I wanted to retrieve the x and y position of mouse both clicking and releasing separately and saved it into variables outside of the function on_click (e.g: px = x position when pressed, rx = x position when…
Alan Koh W.T
  • 413
  • 4
  • 19
4
votes
2 answers

Detecting if a key is HELD down - python

My use case I need to know when a (specific) key is pressed and held down. The use case after detection is fairly easy. When the key is released, send a signal to stop the callback (which I know already). Desired behavior Here is a rough scheme of…
P S Solanki
  • 1,033
  • 2
  • 11
  • 26
4
votes
1 answer

Problems with Pynput and Pyinstaller on Ubuntu 20.04LTS GUI

I have a python script that uses the Pynput module. When I run the python script from terminal on Ubuntu [20.04LTS GUI] it runs perfectly. $ pyinstaller --onefile vTwo.py cd ./dist ./vTwo Error occurs when running ./script: ImportError: this…
arthem
  • 141
  • 3
  • 13
4
votes
3 answers

How to clear keyboard event buffer pynput.keyboard

I have a function that is called on_press. However, if the user constantly hits the key the keyboard event buffer queue gets really large and my function (which takes a few hundreds of ms) gets called even after the user has stopped pressing the…
Varun Nayak
  • 290
  • 1
  • 7
4
votes
1 answer

How can I pass arguments to pynput listener on_press function?

I made a minimal pynput program that does different actions when the left and right arrow keys are pressed. I want to turn this into a function that can take different values as arguments. Here is a minimal working example without a function, and…
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
4
votes
1 answer

pynput is not working with upper case and special characters -- Mac OS

I am learning pynput and working on some projects. pynput is working but it is NOT working when it comes to upper case letters or special characters like !@#$%^&** etc. but . and , are working. Code: from pynput.keyboard import Key, Controller …
WeeeHaaa
  • 475
  • 1
  • 4
  • 10
4
votes
4 answers

Checking a specific key with pynput in Python

dpressed = 0 def on_press(key): if key == ('d'): global dpressed dpressed+=1 logging.info("D: %s" % dpressed) When I run this code and press d, nothing happens, which I suspect is because the key needs to be called…
Mats
  • 89
  • 1
  • 1
  • 7
4
votes
5 answers

pynput keyboard listener does not detect keys on Mac OS X

I am using pynput to record keystrokes via Listener on OS X Mojave. I am using Pycharm as my IDE for running the code. I was not able to get it to work using the same example from the pynput site. from pynput.keyboard import Listener as…
user9990443
4
votes
1 answer

Passing arguments to a pynput listener

Im using pynput listener to catch key presses from keyboard, but the problem is that i need to pass parameter to the on_press and on_release functions and i just can't figure out how to do it. you can see in the code, i need to pass the client…
1
2 3
43 44