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

Re: [pygame] 1.2 on the horizon



> Is there any way to tell whether a pressed key is alphanumeric? I was
> looking for a function like is_alpha(event.key.unicode) or something
> to that matter. But I could only find string.letters and string.digits to
> manually check it.

you're in luck. no need to wait for the next pygame release :]

all string and unicode objects have the following methods

func            true if string contains only
--------------------------------------------
isalnum()        alpha or numeric
isalpha()        alpha
isdigit()        number
islower()        lowercase alpha
isspace()        whitespace
istitle()        lowercase except for first char
isupper()        uppercase alpha

so there you have it. i'm not exactly sure how well these work
with unicode objects and special accented character? but in any
case, you should be able to use these straight from the KEYDOWN
event objects...

if event.type == KEYDOWN:
    if event.unicode.isalnum(): print 'Good Job', event.unicode
    else: print 'Try Again'




____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org