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

[pygame] Re: Problem with event-handling



Kai -

Pygame already does something like this - key.get_pressed. You can either use it directly or you can rewrite is_pressed like this:

from pygame import key

def is_pressed(theKey):
   return key.get_pressed()[theKey]

HTH,
Taylor

----- Original Message ----- From: "Kai Kuehne" <kai.kuehne@xxxxxxxxx>
To: <pygame-users@xxxxxxxx>
Sent: Wednesday, October 25, 2006 4:34 PM
Subject: Problem with event-handling



Hi list!
I wanted to create a function which get a key and returns
true/false whether the key is currently pressed:

def is_pressed(key):
   pygame.event.pump()
   event = pygame.event.poll()
   if event.type == KEYDOWN:
       if event.key == key:
           return True
       return False

When I use this function: is_pressed(K_SPACE), it doesn't work.
The variable "key" always contains 27 (ESC). Can anybody
point me to my mistake(s)?

Thanks
Kai