[Python-de] 2004q3/005539.html
Hartmut Fröls
froels at panno.com
Die Aug 17 11:52:41 CEST 2004
gquell at skequell.de wrote:
>Hallo Leut,
>
>~ versuchs mal so:
>
>
>#!/usr/bin/env python
># testprogramm getchar
>
>import os, sys
>import termios
>
>def getch():
>
>~ fd = sys.stdin.fileno()
>~ if os.isatty(fd):
>
>~ old=termios.tcgetattr(fd)
>~ new=termios.tcgetattr(fd)
>~ new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
>~ new[6] [termios.VMIN] = 1
>~ new[6] [termios.VTIME] =0
>~ try:
>~ termios.tcsetattr(fd, termios.TCSANOW, new)
>~ termios.tcsendbreak(fd,0)
>~ ch = os.read(fd,7) # vorher: 7
>~ finally:
>~ termios.tcsetattr(fd, termios.TCSAFLUSH, old)
>~ else:
>~ ch = os.read(fd,7)
>
>~ return(ch)
>
>if __name__ == "__main__":
>~ print "Zeichen eingeben" ,
>~ cc=getch()
>~ for j in cc: print "%x" % ord(j),
># End getchar.py
>
>
>Gruß Gerhard
>
Sorry, da war ich wohl missverständlich.
Das Problem liegt nicht in dem termios-Zweig, sondern bei dem
2. read, wenn stdin nicht als tty erkannt wird !