Answer the question
In order to leave comments, you need to log in
Looping while a key is pressed in python?
It is necessary to implement a loop while the key is held down, and when it is released, do not loop, and so on ad infinitum. Tried it in different ways, for example
import keyboard
while True:
try:
if keyboard.is_pressed('n') :
keyboard.press('space')
except:
break
import keyboard
while True:
try:
if keyboard.is_pressed('space') == True:
keyboard.press('space')
keyboard.wait('space')
except:
break
Answer the question
In order to leave comments, you need to log in
Try like this:
import keyboard
while True:
if keyboard.is_pressed('space'):
pass
Maybe learn python first? Heard anything about if-elif-else? Do you know what try-except does in your code? Do you know what while is?
Here is the solution to the problem:
while keyboard.is_pressed('space'):
keyboard.press('space')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question