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

Re: [pygame] Handling keys

On Wed, 6 Jun 2001, Pete Shinners wrote:

>> 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)

Great! I never thought about that 'unicode' part of the event, as I've
always just used the 'key' field. Can those characters be assembled into
a string without problems? Hmm, I'll just try it out, everything should
be spoonfed... :-)

Thanks for the help, Pete.

Jan 'Chakie' Ekholm |     Balrog New Media    http://www.balrog.fi/
   Linux Inside     | I'm the blue screen of death, nobody hears your screams

pygame mailing list