Is it possible to use pygame to input input from the console, instead of displaying a separate window for inputting input? I use pygame to track how long the keys on the keyboard have been pressed.
The following code does not work (this is just a minimal example, it does not actually track the elapsed time):
pygame.init() while 1: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: print event.key, 'pressed'
It doesn't seem like any pygame event is being raised. If I add
screen = pygame.display.set_mode((640, 480))
After
pygame.init ()
then the event will be raised, but I have this terrible window that I do not want to deal with.
To explain why I do not want this window, I imagine that this application is a command line utility, so I can not do this. Is there any functional reason preventing pygame from running on the command line?
Thanks!
EDIT: I assumed that the problem was pygame.init (), and that I only needed to initialize the key and event modules. According to http://www.pygame.org/docs/tut/ImportInit.html I should have called
pygame.key.init ()
pygame.event.init ()
but that didn't work.
source share