Skip to content
Advertisement

Non-blocking console input?

I am trying to make a simple IRC client in Python (as kind of a project while I learn the language).

I have a loop that I use to receive and parse what the IRC server sends me, but if I use raw_input to input stuff, it stops the loop dead in its tracks until I input something (obviously).

How can I input something without the loop stopping?

(I don’t think I need to post the code, I just want to input something without the while 1: loop stopping.)

I’m on Windows.

Advertisement

Answer

For Windows, console only, use the msvcrt module:

JavaScript

For Linux, this article describes the following solution, it requires the termios module:

JavaScript

For cross platform, or in case you want a GUI as well, you can use Pygame:

JavaScript
Advertisement