0
I’m trying to make a program that when I press a key, it reads which key was pressed.
For example:
press the key "a" returns: "Normal Key A" (audio)
press "b" key returns: "Normal Key B" (audio)
press the key "7" returns: "Normal Key 7" (audio)
press the key "!" returns: "Ponctuation Key !" (audio)
press the "Shift" key returns: "Special Key Shift" (audio)
For a reason that I don’t know, it only works normally when the first keyboard is pressed,.
Please help me out!
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()
Isabella didn’t quite understand what you meant by: it only works normally when the 1st keypad is pressed could be a little clearer by kindness?
– gato
@cat when I press the A key, for example, I hear: "Normal Key A", when I press the A key again, I hear: "Nor" (audio does not run until the end.
– Isabela da Silva