reading one byte from stdin

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark McDuff

    reading one byte from stdin

    I'm trying to read one byte from stdin, without the newline.

    If I try something like:
    >>import os, sys
    >>os.read(sys.s tdin.fileno(),1 )
    I can input a character, but then I have to press enter, which leaves
    a newline character in the stdin buffer and requires two keypresses.
    Is there any way to read only one keypress in a simple manner (i.e. no
    curses)?



  • Diez B. Roggisch

    #2
    Re: reading one byte from stdin

    Mark McDuff schrieb:
    I'm trying to read one byte from stdin, without the newline.
    >
    If I try something like:
    >>import os, sys
    >>os.read(sys.s tdin.fileno(),1 )
    >
    I can input a character, but then I have to press enter, which leaves a
    newline character in the stdin buffer and requires two keypresses. Is
    there any way to read only one keypress in a simple manner (i.e. no
    curses)?
    Depending on your OS, yes. Under *nix, you need to set the terminal to
    RAW-mode.

    This recipe claims to be OS-agnostinc:



    Diez

    Comment

    Working...