Keffin
August 28th, 2006, 03:48 PM
I've just been messing around with pygame and have a strange problem with it (not) accepting events. I've condensed it down into a very simple program, but I don't know python at all so I have no idea if it's my fault or pygames...
import os, sys
import pygame
from pygame.locals import *
def main():
pygame.init()
window = pygame.display.set_mode((200, 200))
pygame.display.set_caption('Test')
while True:
for event in pygame.event.get():
if event.type is pygame.QUIT:
sys.exit(0)
elif event.type is pygame.KEYDOWN or event.type is pygame.KEYUP:
if event.key is pygame.K_w:
print "Pressed w"
elif event.key is pygame.K_e:
print "Pressed up"
elif event.key is pygame.K_SPACE:
print "Pressed up"
elif event.key is pygame.K_UP:
print "Pressed up"
elif event.key is pygame.K_ESCAPE:
print "Pressed escape"
else:
print event.key
if __name__ == "__main__":
main()
When I run this and start pressing keys, it recognises the escape key and prints "Pressed escape", the space key is interpreted as the up key and prints "Pressed up", and the others aren't recognised by the elif statements, but the else statement shows that the event.key value is as would be expected (e.g. w shows event.key as 119, which is correct).
If it makes any odds I have a Logitech Cordless Desktop MX3000 keyboard (UK layout) that works perfectly fine for e.g. typing this message. I have tried turning on/off caps lock, num lock etc, but to no avail.
Does anyone know what is happening?
Thanks.
import os, sys
import pygame
from pygame.locals import *
def main():
pygame.init()
window = pygame.display.set_mode((200, 200))
pygame.display.set_caption('Test')
while True:
for event in pygame.event.get():
if event.type is pygame.QUIT:
sys.exit(0)
elif event.type is pygame.KEYDOWN or event.type is pygame.KEYUP:
if event.key is pygame.K_w:
print "Pressed w"
elif event.key is pygame.K_e:
print "Pressed up"
elif event.key is pygame.K_SPACE:
print "Pressed up"
elif event.key is pygame.K_UP:
print "Pressed up"
elif event.key is pygame.K_ESCAPE:
print "Pressed escape"
else:
print event.key
if __name__ == "__main__":
main()
When I run this and start pressing keys, it recognises the escape key and prints "Pressed escape", the space key is interpreted as the up key and prints "Pressed up", and the others aren't recognised by the elif statements, but the else statement shows that the event.key value is as would be expected (e.g. w shows event.key as 119, which is correct).
If it makes any odds I have a Logitech Cordless Desktop MX3000 keyboard (UK layout) that works perfectly fine for e.g. typing this message. I have tried turning on/off caps lock, num lock etc, but to no avail.
Does anyone know what is happening?
Thanks.