When I press a keyboard button on a keyboard with a Russian layout, my application pygame game crashes with this message:
UnicodeEncodeError: 'ascii' codec can't encode character '\u0444' in position 40: ordinal not in range(128)
This is my code:
event = pygame.event.poll()
if event.type == KEYDOWN:
print(event)
(I pressed the latin 'a' key.)
Pressing keys in the English layout works fine.
I tried changing the event.type == KEYDOWN
to event.type == KEYUP
: Everything works, but then I cannot access the event.unicode
field to get the pressed key.
How do I get KEYDOWN
events to work with any keyboard layout?
Python version 3.2
unicode(variable_goes_here)
? \$\endgroup\$