Pygame won't read any uppercase keys

Viewed 43

As an example, when I try to input (through py.event.get()) the ^ (above the 6), the event reads the shift key, but not the six. The same is true for capital letters and @, #, $, %, *, (, and ). The code below is in a while loop. It works for all the keys that don't require a shift.

for event in py.event.get():
    if event.type == py.KEYDOWN:
        keys = py.key.get_pressed()
        if keys[py.K_CARET]:
            print("^")
        if event.type == py.K_CARET:
            print("^")
1 Answers

See How to get keyboard input in pygame?

pygame.key.get_pressed() returns a list with the state of all keyboard buttons. This is not intended to get the key of a keyboard event. The key that was pressed can be obtained from the key attribute (not type) of the pygame.event.Event object. This also works for uppercase keys:

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
        print(event.key, event.unicode)

If this doesn't work for you, this is not a general problem, it is related to your system.

Related