I am making a pygame program where I have a string and whatever the user types it displays it in the pygame window. Here is the code:
if (event.type==pygame.KEYDOWN):
if (event.key==pygame.K_BACKSPACE):
if (len(sin)>0):
sin=""
elif (event.key==pygame.K_RETURN):
if (len(sin)==11):
#sin.replace("-","")
running=2
screen.fill(white)
else:
body=True
else:
sin=sin+chr(event.key)
text=font.render(sin,True,(black),white)
One problem is that it does not recognize special characters like (“:”,”;”,shift characters etc.) Is there a better way to code something like this?
Use
event.unicodeto get what you are looking for.To answer your comment you just check
event.unicodeinstead ofevent.key: