Hi:
I have a problem capturing K_SPACE keydown events with pygame.
The code is:
.... dirty test code........
def OnEvent(self, event):
if event.type == pygame.QUIT:
self._running = False
else:
self.container.objects[0].doEvent(event)
.... more dirty test code.....
def doEvent(self, event):
print `event`
if event.type == pygame.KEYDOWN:
if event.key == K_SPACE:
self.fire()
elif event.key == K_LEFT:
self.moveX(-1)
elif event.key == K_RIGHT:
self.moveX(1)
elif event.key == K_UP:
self.moveY(-1)
elif event.key == K_DOWN:
self.moveY(1)
elif event.type == pygame.KEYUP:
if event.key == K_LEFT:
self.moveX(1)
elif event.key == K_RIGHT:
self.moveX(-1)
elif event.key == K_UP:
self.moveY(1)
elif event.key == K_DOWN:
self.moveY(-1)
That way, if I push the keys rigth and up at the same time an after
the space, the spacecraft shots bullets (executes self.fire()) while
going up and to the rigth... but if i press rigth and dow, left an up
or left and down an after press fire... the spacecraft don't shot!!
-but moves well- O_o Also, the 'print' shows me that no 'keydown'
event for space (nor for alt not altgr) is captured when there is no
fire....
I have solved it by mapping the fire to another key:
if event.key == K_x:
self.fire()
this way works fine, but i have no idea of what is happening... i'm
new in pygame and it can be a knowed issue...
My keyboard is in spanish and my space bar key fires this event:
<Event(2-KeyDown {'scancode': 65, 'key': 32, 'unicode': u' ', 'mod':
4096})>
<Event(3-KeyUp {'scancode': 65, 'key': 32, 'mod': 4096})>
and alt and altgr
<Event(2-KeyDown {'scancode': 64, 'key': 308, 'unicode': u'', 'mod':
4096})>
<Event(3-KeyUp {'scancode': 64, 'key': 308, 'mod': 4096})>
<Event(2-KeyDown {'scancode': 108, 'key': 313, 'unicode': u'', 'mod':
4096})>
<Event(3-KeyUp {'scancode': 108, 'key': 313, 'mod': 4096})>
I have the same problem in my house (ubuntu 9.04) and at work (wXP SP3)