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
0 answers

Python pynput failed to acquire x connection

Im getting the error 'failed to acquire X connection: cant't connect to display ":0": No protocol specified\n' echo $DISPLAY results in :0 I've tried $ DISPLAY=:0 python -c 'import pynput' I'm running ubuntu in virtual box on a win10 machine trying…
2
votes
0 answers

Python: How to change a keyboard layout in the keylogger?

I am doing keylogger that prints the key I pressed. And I have a problem. When I change my keyboard layout the layout does not change. Please help me. from pynput.keyboard import Key, Listener def on_press(key): print('{0} pressed'.format( …
AkiRus
  • 21
  • 2
2
votes
1 answer

How to combine callback-based library with asyncio library in Python?

I have the following issue. I want to read out keystrokes with the pynput library and send them over websockets. Pynput proposes the following usage from pynput import keyboard def on_press(key): try: print('alphanumeric key {0}…
Seism0h
  • 21
  • 2
2
votes
2 answers

How to use pynput via ssh on an embedded computer

I'm trying to run on an embedded computer (hence with no display) a module using pynput package. I'm connected via ssh to the embedded computer (which is on Linux) and when I try to run the script I get this error : Traceback (most recent call…
Rémi
  • 21
  • 2
2
votes
1 answer

How to import python packages while using it in node.js application in VS code

I am developing a quiz application in node.js. I need some python script to keep log of user,so I want to use key logger to keep monitoring the user while attempting the quiz. Here is the python keylogger script: from pynput.keyboard import Key,…
Hammad Ali
  • 331
  • 3
  • 12
2
votes
2 answers

pynput events executing twice

def pressLetter(charIn): val = getKeyValue(charIn) PressKey(val) return def KeyboardEvents(): from pynput import keyboard with keyboard.Events() as events: for event in events: if event.key == keyboard.Key.space: …
2
votes
1 answer

Automatically Click Mouse at Random location using pynput (for a web browser game)

Info. Hey there :) I'm learning Python for a few weeks now, and I just started with some small projects. Now I'm building a script to automate an webbrowser game. The script sends out a few "expeditions" which give me more rescources inside the…
IdseB
  • 23
  • 4
2
votes
1 answer

Works in terminal but not in VS code

I have a problem that just drives me crazy. I have a python script, that works when I run it in the terminal (ubuntu) but not in vscode. The terminal code is just: python helper.py and the helper.py looks as follows: from pynput.keyboard import Key,…
Paul Schal
  • 21
  • 1
  • 2
2
votes
1 answer

Pynput - Restart Listener(or start a new one)?

I am using the pynput module and I want to restart a listener after a specific rule - condition - key combination is fulfilled. The code I have written is shown below : from pynput.keyboard import Key, Listener from langdetect import detect from…
ppel123
  • 83
  • 3
  • 10
2
votes
0 answers

Simulate long key press (press and hold) using pynput

I'm using python3.6 and installed pynput through pip. I want a functionality to simulate a long key press (press and hold) of a key. I tried commenting the release() function hoping that it will work as long press but only the key is pressed single…
Surya
  • 971
  • 2
  • 17
  • 30
2
votes
0 answers

How to convert special key codes of a pynput listener

My problem is when I listen to a key combination of like Ctrl + V the key logger shows me that the pressed keys are [Ctrl, '\x16'] (I am showing it on an array). So, my question is, Can someone tell me a way of converting this key code to the right…
Hyperx837
  • 773
  • 5
  • 13
2
votes
4 answers

How do I pass an argument in a function that is called without parentheses?

This is an example code from the pynput documentation. It basically prints the key you are pressing. from pynput import keyboard def on_press(key): print('You pressed {}'.format(key)) if key == keyboard.Key.esc: return False with…
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
2
votes
2 answers

pynput keyboard listener causes delays

I am making a program that toggles on and off by a certain key on the keyboard (using pynput). I placed the keyboard listener loop in the first thread, and the action loop in the second. The problem is that after I start the code, it doesn't listen…
Mirrah
  • 125
  • 2
  • 9
2
votes
2 answers

PySimpleGUI Freezes

I wrote a code for a hack in a game cold Boxing Simulator 2 in python 3.8.1 with PySimpleGui 4.15.1, and if I try to Click the start/stop button, the gui Freezes but the script connected with the Start/Stop button still runs. But if i change the…
user10763624
2
votes
2 answers

How to Stop Keyboard Listener after a particular time?

I have a Function which keep listening.. I want to stop the Listener after a particular time import time from pynput.keyboard import Listener with Listner(on_press=onPress) as l: l.join this is an Endless Loop... i want to Stop the listener…
Mohit Jain
  • 25
  • 1
  • 6