I'm trying to make a program that, when I press a key, it reads which key was pressed.
For example:
Press the "a" key to return: "Normal Key A"
I press the "b" key to return: "Normal Key B" (in audio)
press key "7" returns: "Normal Key 7" (in audio)
press the "!" key. returns: "Ponctuation Key!" (in audio)
Press the "Shift" key to return: "Special Key Shift" (in audio)
For a reason that I do not know, it only works normally when the 1st key is pressed, from the second the audio is cut.
Please help me!
import pyttsx
engine = pyttsx.init()
from Tkinter import *
def key(event):
if event.char == event.keysym:
msg = 'Normal Key %r' % event.char
elif len(event.char) == 1:
msg = 'Punctuation Key %r (%r)' % (event.keysym, event.char)
else:
msg = 'Special Key %r' % event.keysym
label1.config(text=msg)
engine.say(msg)
engine.runAndWait()
root = Tk()
prompt = ' Press any key '
label1 = Label(root, text=prompt, width=len(prompt), bg='yellow')
label1.pack()
root.bind_all('<Key>', key)
root.mainloop()