I am trying to write a python typing test that displays 5 letter words from a list in a timed while loop of 60 seconds. Everything works if the user presses enter after each typed word but this allows for backspacing and isn't my goal. Is input() able to move on after 5 keys have been typed (including arrow keys and backspace key) without the enter key press? Just moving on to the next word as if enter was pressed?
import time
import random
t_end = time.time() + 60 # Set timer for 60 seconds
correct = 0
incorrect = 0
wpm_count = 0
accuracy = 0
words=["buggy", "coder", "etc.."] #TODO: put lots of 5-character words in a list
while time.time() < t_end:
for word in random.sample(words, 1):
print(word, end=" ")
wpm_count += 1
user_txt = input(" ")
if (user_txt == word):
correct += 1
else:
incorrect += 1
#Calculate and display results
accuracy = (correct / attempts ) * 100
print("=-=-=- Results: -=-=-= \nCorrect: " + str(correct) + " \nErrors: " + str(incorrect) + " \n Total WPM: " + str(attempts) + "\nAccuracy: " + str(accuracy) )