I'm trying to make a program to send messages repeatedly and is able to be paused on space bar press and unpaused after another space bar press. I'm not sure how to constantly check for key presses while the program is running. Here is my code
import pyautogui
import random
import string
import time
phrase = str()
n = 0
while True:
if n < 5:
for i in range(random.randint(1,10)):
letter = random.choice(string.ascii_letters)
phrase = phrase + letter
print(phrase)
pyautogui.typewrite(phrase)
pyautogui.press("enter")
phrase = str()
n = n + 1
time.sleep(0.005+0.001*random.randint(1,10))
else:
pyautogui.keyDown("alt")
pyautogui.press("tab")
pyautogui.press("tab")
pyautogui.keyUp("alt")
n = 0