N
N
nemoigollos2020-05-16 16:17:45
Python
nemoigollos, 2020-05-16 16:17:45

Bug when executing a while loop in python?

There is, for example, this code:

spoiler
while True:
    if keyboard.is_pressed('n'):
        while keyboard.is_pressed('n'):
            keyboard.press_and_release('B')
            time.sleep(0.05)
    else:
        pass


The problem is that sometimes there is a bug in which B cycles endlessly when the N key is pressed.
With a large delay, 0.5 s or more, this does not happen; B cycles while the N key is pressed, and when it is released, it does not cycle.
Without time.sleep, it goes to infinity, no matter what you do to it.
Where did I pierce or how can I fix it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question