[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Handling keys

> Does anybody have any good hints for handling keys easily? I need to
> handle a lot of various keys and combinations as I need to let the player
> type normal text. The text contains upper/lowercase letters, special
> character such as ()!#_:;%&/ and so on. Normal lowercase letters, digits
> and stuff that can be retrieved without any modifier key is easy to
> handle, as I can simply get the name of the key, like this:

you're in luck, there is an easy solution!

each KEYDOWN event also comes with a "unicode" field. this is 
the properly translated character created when a key is pressed.
it respects all the keyboard settings.

from there you may want to into encode it into anormal string, or
perhaps let it remain as unicode. the Font.render() routine accepts
unicode text, so you can properly render all those extended characters.
(as long as your truetype font has unicode chars)

pygame mailing list