Unbuffered keyboard input

apighin at my-deja.com apighin at my-deja.com
Tue Nov 7 16:33:27 CET 2000


Sorry, a bit of a newbie question here.  I am just learning Python, and
am going through 'Learning Python' by O'Reilly.  I am looking for a way
to open the keyboard/console as unbuffered.  Here is their example:

while 1:
    next = sys.stdin.read(1)
    if not next:
        break
    <process character 'next'>

I have tried this, but the system input still seems to be buffered.
Not until Enter is pressed does the processing of any of the input
characters occur.

What I would like to be able to do is do a stdin.read(1), and if no
character is available, just go to the top of the loop and try again.
I have looked at the Curses getkey() and getch(), but I don't really
want Curses.  Also, I have tried to open the /dev/console and /dev/kbd
as unbuffered, but I get a 'Permission denied' error.

Any help is appreciated.

Anthony


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list