'how to detect WASD keypresses on PyGame [duplicate]
I am trying to detect the WASD keys being pressed on the keyboard, however, it won't detect the keypresses. Other answers on Stack Overflow didn't help so I don't think this is a duplicate.
Here is the relevant code:
level = 0
abort = False
while not abort:
for event in pygame.event.get():
if event.type == pygame.QUIT:
abort = True
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_SPACE:
if onPlatform == True:
onPlatform = False
ytarget = ylevel + 100
if event.type == pygame.K_a:
print("a")
xlevel = xlevel-2
if event.type == pygame.K_d:
xlevel = xlevel+2
Here is the error I get (fixed):
if event.type == pygame.K_A:
AttributeError: module 'pygame' has no attribute 'K_A'
EDIT: comments suggested making K_a lowercase, this has fixed the error, but is now simply not responding to keypresses.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
