I am just starting to learn python for a project, which requires keyboard input. From what I've read, pygame is the best way to do this. Unfortunately I've been unable to get KEYDOWN
to work. The only event pygame.event.get()
returns is MOUSEMOTION
.
The code I need would go something like this:
import pygame
def main():
pygame.init()
while True:
for event in pygame.event.get()
if(event.type == pygame.KEYDOWN)
if(event.key==pygame.K_LEFT)
cry_because_it_worked()
I'm not sure what I'm doing wrong. I've read a few other questions about keyboard input, and all of them suggest using code that as far as I can tell is identical. For example, the first code block of the first answer to this question: How to get keyboard input in pygame?
pygame.init()
returns (6,0)
, which I believe means that all modules were initialized correctly. I'm using python 3.4.3 and pygame 1.9.2. Any help would be greatly appreciated.
Edit: Here is the actual loop in my code:
import pygame
...
def handleKeyInput(enigma):
pygame.init()
print("before loop")
while True:
for event in pygame.event.get():
print(event.type) #Always prints 4, which is the value of MOUSEMOTION
print(event.type == pygame.KEYDOWN) #Always prints false
if event.type == pygame.KEYDOWN:
#and then a bunch of if statements for all letters