> I am looking to create a telnet client that will, by using the select()
> statment, poll an open socket for data to be received while at the same time
> keep accepting keyboard input from the user.
>
> I have tried to run a thread in the background that collects input, but I
> never can figure out how to achieve the 'fluidity' that I desire--i.e. no
> stopping for a return-key press.
I think this ought to work for some platforms:
try:
istty = sys.stdin.isatty()
except AttributeError:
istty = 0
if istty:
if os.name=='posix':
import tty
tty.setraw(sys.stdin.fileno())
elif os.name=='nt':
import win32file, win32con
hstdin = win32file._get_osfhandle(sys.stdin.fileno())
modes = (win32file.GetConsoleMode(hstdin)
& ~(win32con.ENABLE_LINE_INPUT
|win32con.ENABLE_ECHO_INPUT))
win32file.SetConsoleMode(hstdin, modes)
Unfortunately, GetConsoleMode, SetConsoleMode, and associated
constants don't seem to be included in win32all yet!
--
Any opinions expressed are my own and not necessarily those of Roundpoint.
--- Begin Demo Script
from msvcrt import *
ch = 0
while ch != 'x':
if kbhit():
ch = getch()
print ch
--- End Demo Script
Dave
On 27 Feb 2001 15:54:55 -0800, Ben Hutchings