[Tutor] user input without return / non-blocking

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri May 16 16:57:01 2003


On Fri, 16 May 2003 ccollier@viawest.net wrote:

> I'm working on a small console based game.  I need to be able to accept
> input from a user (keyboard/stdin) without having them press return.  j
> = move left, k = move right etc.
>
> sys.stdin.read, input, and raw_input don't seem to be the solution I'm
> looking for, although sys.stdin.read is close.
>
> Can anyone point me in the right direction?


Hi Cody,


Here you go:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892

The code from the link provides a function called 'getch()' that should
behave the way you expect.



But if you're interested in programming games, you might want to look into
PyGame as well:

    http://pygame.org/

It'll let you write graphical games, and provides functions for doing
keyboard input too.



Good luck to you!