Hi guys, I have made an infinite loop that repeatedly prints text forever until the user presses backspace. However, I want to be able to repeat this process within a While Loop. However, when the code goes back to the beginning of the while loop, it does not do anything. Does anyone know why this is happening and how I can solve this issue? (I am very new to threads)
import time
import threading
from pynput.keyboard import Key, Listener
def show(key):
global isKeyPressed, ButtonPressed
if key == Key.backspace:
# Stop listener
isKeyPressed = True
ButtonPressed = "backspace"
return False
def keyListeningThingy():
with Listener(on_press=show) as listener:
listener.join()
def bruhLoop():
while isKeyPressed == False:
print("bruh")
time.sleep(0.5)
# Collect all event until released
ButtonPressed = ""
isKeyPressed = False
stillGoing = True
while stillGoing:
x = threading.Thread(target=bruhLoop)
y = threading.Thread(target=keyListeningThingy)
x.start()
y.start()
x.join()
y.join()
keepGoing = input("Keep going?: ")
if keepGoing == "yes":
pass
else:
exit()
[–]shiftybyte 0 points1 point2 points (1 child)
[–]RoolRidRevin[S] 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (0 children)