Skip to content Skip to sidebar Skip to footer

How Do I Get Realtime Keyboard Input In Python?

Is this possible? Every answer I have looked at isn't what I want. What I do though is something like in omega-rpg (which is an awesome little text-based debian rpg), but in Python

Solution 1:

I think using raw_input() in a while loop is an acceptable solution.

You could also look into something like pygame which would handle the main game loop for you and also offers input handling.

Solution 2:

If you are using Windows you can use the msvcrt module. Specifically, look at kbhit to check whether a key is waiting to be read and getch to read a key press. The user does not need to press enter for the key presses to be made available to your program.

Solution 3:

You could look into PyHook. It provides callbacks for reading mouse and keyboard events.

Post a Comment for "How Do I Get Realtime Keyboard Input In Python?"