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
2
votes
1 answer

How can I ignore all user inputs for duration of function run?

I have a Python module that listens for a key combination using pynput then, once it's pressed, it types a string into a text program. It works great! Except... In the example below, the user's key combo is set to shift + space. This makes a lot…
Matt W
  • 129
  • 1
  • 7
2
votes
1 answer

Listening for specific keys with pynput

I'd like my code to listen for user input, and do something if key c is pressed, and something else if key v is pressed. I've managed to do it using global, but it feels like an ugly hack : from pynput import keyboard def on_press(key): try: …
François M.
  • 4,027
  • 11
  • 30
  • 81
2
votes
2 answers

How to run pynput.Listener simultaneously with tkinter.Tk().mainloop()

I am a teacher. I teach math, but since education is facing human resources crisis, I have some additional duties. I teach kids a bit of programming, they do quite well. Now I'd like to make with them a snake game, but I have a problem achieving…
Andrze
  • 23
  • 1
  • 3
2
votes
1 answer

Issue in a code to register first 100 key pressed and length

Need you help, it works only for the first one... The idea is to register first 100 keypresses with the time and the length they are pressed. from pynput import keyboard import time, os tinit = time.time() Resultatfichier=open('Keyregister','a') x…
diben lax
  • 23
  • 3
2
votes
1 answer

Pynput shows wrong mouseposition data

For some reason I get wrong mousepointer positions with pynput. The 0,0 position is right and the 1920x1080 position is right but in between there is an error of around 100px. from pynput.mouse import Listener def on_click(x, y, button, pressed): …
nanobot
  • 108
  • 5
  • 18
2
votes
2 answers

How to simulate key press event in python on another program running in python

I am running ML model, which predicts fingure gestures.I am trying to simulate key press event in python using pynput library and I check it's working fine.But I have other program which Is a game written in python using pygame library , which opens…
Aviii04
  • 21
  • 1
  • 5
2
votes
0 answers

How to simulate key presses on a specific application

I'm trying to set up a bot that does things for me, at the moment I have to be in the same window so that it works. Is it possible to be able to change my window (e.g using google chrome) while the bot is running on that specific application? Also…
Elpupper
  • 46
  • 1
  • 12
2
votes
0 answers

pynput does not appear to handle caps lock key

Using pynput with Windows 10, Python 3.7, the character code returned reflects the state of the caps lock key when the program was started. Changes to that key do not lead to changes in the value returned. from pynput import keyboard def…
David C
  • 21
  • 3
2
votes
1 answer

Interact with pc in python (mouse+screenshot)

I'm writing a bot that interact with the pc. Briefly what I do is: -Take a screenshot of the screen -recognize an object (with cv2 matchTemplate) on this screenshot -make some mouse action using the position found (example: move the mouse pointer…
user254087
  • 51
  • 5
2
votes
1 answer

Can I get a function for when I click the mouse a second time (not on the current window)

first off I am new to programming and just learning the basics at the moment. I am creating a 'product picker' using python 3.7 (in pycharm) and want to mouse click on one of the product buttons then on my next mouse click paste/print/insert the…
2
votes
3 answers

Pynput listener doesn't allow if statements with alphanumeric characters

I'm trying to create a piano keyboard in Python using Jazz-Plugin for sending the MIDI messages and Pynput listener to register the keystrokes. My problem is that I want the lowest note to be on the Z key. I can't seem to find a way to get my if…
N. Hooley
  • 41
  • 4
2
votes
0 answers

OpenCV error -215:Assertion Failed, can't figure out how to diagnose this error

I've been following a tutorial for developing a template matching bot for the flash game Burrito Bison, github with code linked here but even with the original source code can't seem to get the bot to run. The error appears to be with the line res…
Joe Howard
  • 307
  • 5
  • 27
2
votes
1 answer

Pynput same Controller keyboard and mouse

I know the Problem but dont how to fix it. Controller gets overwritten but how can I change that? import pynput from pynput.keyboard import Key, Controller from pynput.mouse import Button, Controller keyboard = Controller() mouse =…
Leo
  • 23
  • 1
  • 6
2
votes
1 answer

Python: Recording Keystrokes and Mousemovement simultaneously

i cant find a solution for the following problem: I would like to record keystrokes and mousemovement at the same time. Right now i tried to combine the scripts from the pynput Package Documentation. Monitoring the mouse:…
2
votes
1 answer

Pynput stop listener from "outside"

I started a little backdoor and i use a keylogger in it. I use the pynput library and i wanted to know if it's possible to stop the pynput listener from an outside function or in the main loop. Here is a code snippet : class…
hutchY
  • 31
  • 3