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

Re: [pygame] Problem with event-handling



Sorry, I didnt get the point....  I dont know any Pygame funtion that gives you the char back that was pressed. I guess you have to program it out, means, you have to check for every single pressed key (what about "shift" + "a", etc.?). This can be very expensive inside a loop when checking ALL key inputs. So its definately smarter and faster to check only the ones you really want to check.

In the Pygame doc they write:
...
Both events have a key attribute that is a integer id representing every key on the keyboard.
...

Thats what it does but as far as I've check it the int value is not compatible to the ASCII values what would have made it easier to create a key check function. Maybe you use a kinda internal value translator between the returned event.key value and the ASCII table values. I've quickly checked key "a" and key "b" from event.key:
a = 97
b = 98

They seem to fit the ASCII table list. That way you can directly return the int value converted to ascii value by: chr(event.key)


By default the any key input  is checked in the event queue, so I dont see any reason why to use poll and pump. 

If the order of the pressed keys is important (what it normally does) you should use pygame.KEYDOWN and not pygame.key.get_pressed

Hope I could help this time


Greetings
Farai


Am 25.10.2006 um 23:55 schrieb Kai Kuehne:

Hi,

On 10/25/06, Farai Aschwanden <fash@xxxxxxxxxx> wrote:
Hello Kai

If you only want to check keyboard inputs you dont need to use pump
and pull. Those are, as far as I understand the description, getting
ANY running event from the event queue. So for checkin any key input
you directly can use:  "if event.type == KEYDOWN". If then any key
was pressed you can check for the ones you are interested in. The
following link of Pygame doc shows a list of all available keys you
can  check for.

I know this, but I simply didn't want to use it that way.
The problem was that I pulled for ESC on the of the loop and later
I pulled for SPACE. Logically, the queue is always empty, when
I check whether SPACE is pressed.

I would be great if I had a key-system that works like, e.g.:
input.is_pressed(KEY, FUNCTION)

and internally it uses a list and calls the given function
every time the key is pressed. The internal things should be
hidden from the programmer. But I'm not that pro and have
no clue (yet) about this callback-function-thing.

Thanks :)
Kai