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
1
vote
2 answers

Mouse coordinates on Python with PySimpleGUI

I'm trying to get the mouse coordinates, with pynput, and see it with a GUI with PySimpleGUI but I am getting a lot of problens, and I don't know how can I do this. I want to show the mouse coordinates at the "x - y" string below import PySimpleGUI…
1
vote
1 answer

Key repeat after input in pynput

I basically need something to take input from and print it or something else, but whatever I press it will repeat after I (close the program, read text input, etc) here is an example: what I tried: I used the keyboard module instead of pynput…
1
vote
2 answers

Pressing infinite number keys in python

so I wanted to create a code in python that automatically type numbers from 1 to 100 and it doesn't work. Hope someone can help Here's my code from pynput.keyboard import Key, Controller import time keyboard = Controller() n =…
1
vote
0 answers

exit loop pynput thread

Hello i'm trying to make a program to play snake using pynput. When I press space the program runs but even if I press backspace i can't stop it, I know that I have to use threading but I don't figure how it works, thank you my code : from pynput…
Yogeek
  • 11
  • 1
1
vote
1 answer

How to block only one mouse button?

The middle button on my mouse sometimes clicks several times when I click it once. My mouse is expensive and I like it, so I decided to fix it with a program. When I release the middle button, I'd like to freeze it for 0.1 seconds without freezing…
1
vote
1 answer

Python auto clicker, how to listen for mouse events

I can't figure out how to make auto clicks start when I press the left mouse button and stop when I release it. Maybe someone knows how to solve it? Perhaps with the help of pynput it is not advisable to do this, but it is better to use pyautogui,…
deymon
  • 21
  • 3
1
vote
1 answer

OpenCV mouse coordinates differs from pynput mouse.position

I was testing out OpenCV's mouse callback function with pynput.mouse and I realised the coordinates of the cursor are different. Here is the output from the code below. Does anyone know what the offset is as it does not seem to be consistent in the…
1
vote
0 answers

How to stop pynput listener

I'm working on a vim clone made in python, I use pynput to keep track of the current mode (insert, normal), so I'd like so when I press i it switched to insert mode, so i decided to use pynput, to keep track of the inputs, for example, I'd like it…
1
vote
1 answer

python pynput ERROR: failed to acquire X connection: Bad display name ""', DisplayNameError('')

Traceback (most recent call last): File "/boot/system/key.py", line 1, in from pynput.keyboard import Key, Listener, Controller File "/home/user/.local/lib/python3.8/site-packages/pynput/__init__.py", line 40, in from .…
Half Blood
  • 11
  • 6
1
vote
2 answers

How to stop triggering the key while holding the key in pynput?

I am using the pynput and winsound modules to make a program that makes the pc play the sound of the keys and mouse. The problem is that when I press a key and hold it down the key is triggered repeatedly, which causes the sound to play repeatedly…
edif
  • 105
  • 1
  • 9
1
vote
1 answer

How to print list elements one by one by keypress on python

I want to print on the console each word in a sentence, but only when the spacebar is pressed by the user, like this: at the begging nothing happens; then the user press the spacebar and the first word appears and stays there; then he/she presses…
1
vote
1 answer

Make pynput.keyboard listen only when cmd / terminal is in focus. Avoid listening to other key combo events

I am facing a problem here that I am not able to find the solution obviously. I have some code (I will append it at the end) that when a combo of keys is pressed it executes some code. As I explain on title, I am doing this with pynput.keyboard, but…
Zuss
  • 59
  • 7
1
vote
1 answer

pynput, need to trigger only on key presses

Usng pynput, I would like to execute some code only when some keys are pressed. import sys print( sys.executable ) from pynput import keyboard from pynput.keyboard import Key, Controller import time import win32ui import dde import pandas as…
gaut
  • 5,771
  • 1
  • 14
  • 45
1
vote
1 answer

How to Stop mouse Listener with keyboard listener then back it again

I want m_listener to start only when I press f6  and if I clicked F7, it stopped. f6 it again to continue.  My issue is that when I click f7 it totally stops the listener and on_x_y_click never run again if i clicked f6  import pynput import…
1
vote
0 answers

Pynput sent mouse only press and won't release

Hi I wanted to bind extra buttons on my mouse using pynput for playing a game Button.x1 for spam spacebar key Button.x2 for spam left mouse and all of them is trigger for x1 button is worked. but the x2 is more likely holding the left mouse button,…
Abrham
  • 25
  • 4