need definitive answer: capture a keypress

robin at brainexeculink.com robin at brainexeculink.com
Wed Aug 15 08:16:11 EDT 2001


This question comes up so often, it's ridiculous. I've read all the
Deja threads to no avail.

How can one capture a keypress at the console, in a cross-platform
manner?

In Win32, I simply use getch() and kbhit() from msvcrt. Works great.

On Linux, I can use curses and getch(). But there appears to be no way
of checking for a hit, equivalent to kbhit().

What is worse, curses appears to interact badly with the standard
print statement, and for the life of me I can't figure out how to get
sequential text formatted in a nice simple "print" way, using curses.

There's more: curses leaves my terminal in an unusable state, even
after Python exits. I find this module unusable.

Surely there is an extension that provides can capture a keypress,
without getting into the wild world of curses?

-----
robin
robin at brainexeculink.com
(remove "brain" to reply) 



More information about the Python-list mailing list