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

[pygame] Key Presses



Hello,

This should be a pretty simple question.

I have a 3D multiplayer game where there is a chat box for communication, and I am at the part where the message is entered.  Here is my relevant code so far:


key = pygame.key.get_pressed()
...
for event in pygame.event.get():
    ...
    if event.type == KEYDOWN:
        ...
        elif event.key == K_BACKSPACE and TypingMessage:
            Message = Message[:-1]
        elif TypingMessage:
            name = pygame.key.name(event.key)
            if len(name) == 1:
                if key[K_LSHIFT] or key[K_RSHIFT]:
                    name = name.upper()
                if key[K_CAPSLOCK]:
                    name = name.swapcase()
                Message += name


Unfortunately, this cannot do cases where the uppercase character is completely different from the lowercase character (for example, "?" and "/").  This is exactly the problem.

I looked into the documentation, but I wasn't able to make out how this could be fixed as there were no relevant examples.

Thanks,
Ian