0

event.key doesnt work. I put this code to see if c its printed when i press K_LEFT and nothing.

if (event.type==pygame.KEYDOWN) and (event.type==pygame.K_LEFT):
      pXchange=-0.3
      print ('c')
    if (event.type==pygame.KEYDOWN) and (event.type==pygame.K_RIGHT):
      pXchange=0.3  
      print ('c') 

I tried this way and still not working. The '.key' from "event.key" is white. Should it be like this?

skittels
  • 11
  • 1
  • 1
    The `event.type` cannot be equal to `KEYDOWN` and `K_LEFT` at the same time (unless `KEYDOWN` and `K_LEFT` are the same, obviously). – Selcuk Dec 20 '21 at 23:42
  • Your second comparison should be `event.key==pygame.K_LEFT` – import random Dec 20 '21 at 23:43
  • I tried this way too, it doesn't work either. while running: pygame.display.update() event=pygame.event.poll() for event in pygame.event.get(): if event.type == pygame.QUIT: running=False pygame.QUIT if event.type==pygame.KEYDOWN: if event.key == pygame.K_LEFT: pXchange=-0.3 print ('c') if event.type==pygame.KEYDOWN: if event.key==pygame.K_RIGHT: pXchange=0.3 – skittels Dec 21 '21 at 13:07

0 Answers0