Skip to content
Advertisement

How to pause a pynput event listener

I am trying to make a program that will read the user’s inputs and if it detects a certain key combination, it will type a special character. Currently I am testing and I want the script to just output a ‘+’ after each character that the user types. I am using the pynput event listener to determine if a key was pressed and using a ‘Pause’ variable so that the output of the ‘+’ doesn’t cause the event listener to make an infinite loop. The problem is that the event listener is going into an infinite loop anyway and I am not sure why.

Current typed output after each key press: +++++++++++++++++++…

Desired typed output after each key press: +

Current console output after each key press:
pause is False
getting pressed
getting released
[‘f’]
paused
send outputs
unpaused
pause is False
getting pressed
getting released
[‘+’]
paused
send outputs
unpaused
pause is False
getting pressed
getting released
[‘+’]
paused
send outputs
unpaused
pause is False
getting pressed
getting released


Desired console output after each key press:
pause is False
getting pressed
getting released
[‘f’]
paused
send outputs
pause is True
unpaused

JavaScript

How can I fix my code to *actually* pause the event listener. I am new to python, so I might just not understand how to update global variables correctly.

Advertisement

Answer

You have to stop the listener before using the keyboard controller. I hope this code helps out, I tried to get as close to what I thought you were looking for.

code:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement