I'm having trouble using the keyboard module. I'm working on a typing game in turtle graphics. The user types and a "guide" arrow above the sentence shows the user how far they've typed. The arrow is supposed to turn red when an incorrect letter is typed, and it turns green when a correct letter is typed.
Knowing if the user has typed the correct letter is no problem, I'm using keyboard.is_pressed()
to move the arrow forward and change green. However, the incorrect part is the problem. I need to use a function that returns the value of a any key, not a specific key. If it returns the value of the key the user types, then I can see if it is incorrect or not.
I tried using the conditional: if keyboard.read_key() != letter:
which does what I want, but since I am using keyboard.is_pressed()
to see if the letter is correct or not, the arrow only changes green for an instant, and then goes red. This is the code I am using:
count1 = 0
while True:
if x[count1].isupper():
if keyboard.is_pressed(x[count1]) and keyboard.is_pressed('shift'):
carmove()
arrowmove()
count1 += 1
try:
if keyboard.read_key() != x[count1]:
incorrect()
except:
IndexError
else:
if keyboard.is_pressed(x[count1]):
carmove()
arrowmove()
count1 += 1
try:
if keyboard.read_key() != x[count1]:
incorrect()
except:
IndexError
if count1 == length1:
break
x[count1]
is a specific letter in the sentence. This code causes the arrow to turn green for second, then it goes right back to red.
I also tried making a list of all of the printable characters, then remove the correct letter the user must type, and then iterate through the list but that didn't seem to work either.
I read through the API docs for the keyboard module, but I couldn't find anything else that might work. I'm wondering if it is possible to use the keyboard module, or if I have to use another module. Any help is appreciated.