[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Unprintable characters



Clean slate.

UniCode does not seem to be completely functional in SDL. As this thread from 2006 suggests (http://old.nabble.com/Arrow-Keys,-and-keysym.unicode,-SDL-1.2.10-td5030718.html) you may need to do some platform-specific special handling of certain keyboard events. The SDL version used in Pygame may have changed in the last four years, but the behavior does not indicate so. Of course, there is still the possibility that I am a floundering UniCode noob. I'm sure one of the Pygame devs could clarify.

Check this out.

##begin python##
import unicodedata
import pygame
from pygame.locals import KEYDOWN
pygame.init()
pygame.display.set_mode((10,10))
while 1:
    for e in pygame.event.get():
        if e.type == KEYDOWN:
            print 'key', e.key
            print 'unicode len', len(e.unicode)
            print 'unicode name', unicodedata.name(e.unicode, 'no name')
            print '--break--'
##end python##

The following output is on a Compaq 6910p Windows XP laptop, Python 2.5.4, Pygame 1.9. I can't explain why Python's name lookup is failing on a carriage return, or why the two Intel platforms I have access to (Windows and Ubuntu) return an event.key that is greater than an 8-bit value for cursor keys.

##begin program output##
key 32
unicode len 1
unicode name SPACE
--break--
key 13
unicode len 1
unicode name no name
--break--
key 273
unicode len 0
unicode name
Traceback (most recent call last):
  File "C:/tmp/unicode.py", line 11, in <module>
    print 'unicode name', unicodedata.name(e.unicode, 'no name')
TypeError: need a single Unicode character as parameter
##end program output##

A Ubuntu 8 Compaq desktop, Python 2.5.2, Pygame 1.7.1, produces the same results.

Gumm