[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] BUG: pygame.event.get(pygame.KEYDOWN) fails
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] BUG: pygame.event.get(pygame.KEYDOWN) fails
- From: René Dudfield <renesd@xxxxxxxxx>
- Date: Sun, 3 May 2009 09:15:34 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sat, 02 May 2009 19:15:36 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=RG64mWwVzTzE15S0d7kE0q4jpfArz2zS/6F6qNc3XBk=; b=kJLZMYHolonRcbwdbOz4jX3Kg6ckW45SgyWDoFZerwXRQfz3SnR5j5N8AIFnBrlfsC yklYUmKyxPgVzLKOI+DYDd4bZw66pooyCrwWUMhccJbUT9AHOE6dx4tQKbmScwCAAeHA guy4MUNjeFxb072YqZY/FUy+JwiHuMvALrRBc=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=OX3rjeK0Ek/znTASmZHwPShkS6vYIlnEgSADUjByY26iESK+UVPx3jqc3/lJOrt6Nj 9VTayyl+L2G3DPmDsaEWrVLIO8/auvBIwtYq005PUXjzVsEZPYh5ariM4ABJuPyEjrKn djeeUcSN2h9vHXy40vRyVwxEf+U2jg23bw4Hw=
- In-reply-to: <49FCCB55.20500@xxxxxxxxxxx>
- References: <49FCCB55.20500@xxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
hi,
why this isn't working, is because when you pass in an event type it
leaves the other events in the queue. Which means at some point the
queue fills up, and no other events can go on there.
It's not the nicest behaviour... but is working as specified. It
would be better if it could tell you this was happening. Maybe with a
warning message somewhere... I'm not sure the best way. Since, for
some programs, this behaviour is ok.
So I think at least a warning in the documentation for
pygame.event.get(type) is in order.
If you clear the event queue at the end of your loop, it should work.
You can clear the events every loop like this:
#was broken, now working
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
counter = 0
while 1:
pygame.time.wait(60)
for event in pygame.event.get(pygame.KEYDOWN):
counter +=1
print counter
pygame.event.clear()
#this is probably better... getting all the events off the queue each round.
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
counter = 0
while 1:
pygame.time.wait(60)
events = pygame.event.get()
for event in events:
if e.type in [pygame.KEYDOWN]:
counter +=1
print counter
On Sun, May 3, 2009 at 8:38 AM, evilmrhenry <evilmrhenry@xxxxxxxxxxx> wrote:
> Tested under Linux. (Python 2.5.4, pygame 1.7.1 release 4.2 from Debian)
> and Windows. (with a slightly older version of python/pygame)
>
> The code pygame.event.get(pygame.KEYDOWN) does not work correctly. If
> called in this manner, it will work, but only for the first 100 or so
> keypresses. After a certain point, the get() function will no longer
> return the appropriate events, and will instead return an empty list, no
> matter what the physical input. pygame.event.get() functions properly.
>
> Below is some test code. When running the first program, the counter
> tends to stop at around 120. The 2nd program, which should be identical,
> functions as expected.
>
>
>
> #Broken
> import pygame
> pygame.init()
> screen = pygame.display.set_mode((640, 480))
> counter = 0
> while 1:
> pygame.time.wait(60)
> for event in pygame.event.get(pygame.KEYDOWN):
> counter +=1
> print counter
>
> -----------
>
> #Works
> import pygame
> pygame.init()
> screen = pygame.display.set_mode((640, 480))
> counter = 0
> while 1:
> pygame.time.wait(60)
> for event in pygame.event.get():
> if event.type == pygame.KEYDOWN:
> counter +=1
> print counter
>
>