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

Re: [pygame] raw_input() and pygame.event.get()



Mike Wyatt wrote:
Pete Shinners wrote:
On Sun, 2006-12-10 at 22:12 -0600, Mike Wyatt wrote:
Oops, I forgot to mention that. I'm using raw_input() because I want
to focus on getting my game working before putting time into writing a
GUI. Without a GUI, the only way I can get user input is with
raw_input(). I'm working on my networking code, so I need to have
each game instance ask the user (i.e. myself) to host a new game or
join an existing game.

Use the pygame event filtering to block certain event types. Turn this off and on around your input_raw call.

http://pygame.org/docs/ref/event.html#pygame.event.set_blocked

pygame.event.set_blocked(pygame.KEYDOWN | pygame.KEYUP)
value = raw_input()
pygame.event.set_blocked(None)



That code doesn't block the events. They still appear in the next call to pygame.event.get(). Here is a script you can run to verify this:

*************************************
import pygame

pygame.init()
displaySurface = pygame.display.set_mode( (400, 300), 0 )

while True:

for event in pygame.event.get():
print event
if event.type == pygame.KEYDOWN and event.key == pygame.K_s:
pygame.event.set_blocked(pygame.KEYDOWN | pygame.KEYUP)
value = raw_input("Type some stuff (include the 's' character): ")
pygame.event.set_blocked(None)
print "You typed", value
pygame.display.flip()
*************************************



pygame.display.flip() didn't have the appropriate indentation. It should be corrected now (above). Has anyone run this and confirmed my problem?