[Tutor] Telnet and special characters

David Perlman dperlman at wisc.edu
Wed Feb 28 15:31:48 CET 2007

This question isn't well posed.  There is no such thing as an F1  

Data is sent over telnet connections as 8-bit bytes.  You can send  
any combination of 8-bit bytes you want by coding them in a number of  
different ways, such as chr(xx) like you wrote below, or '\xnn' or  
whatever suits your fancy.  The reason you are having problems is  
that you don't know what bytes you want to send over the connection.   
If you figure that out, then you will be able to send those bytes  
without any further trouble.

If you're having trouble figuring out what bytes you want to send  
over the connection, you need to take a step back and ask what it is  
you're actually trying to do.  What are you sending the data to?  Are  
you trying to emulate something else that would normally be sending  
the data?  Find the documentation for the sending and/or receiving  
ends, and figure out what combinations of characters, escape  
sequences, whatever, are involved in triggering the behavior that you  
want.  Then you will know what bytes you want to send.

If you are emulating something else on the client end, you could fire  
up the regular client and sniff the connection while you hit whatever  
'F1' key you're interested in, and see what actually gets sent over  
the connection when you do that.

On Feb 27, 2007, at 12:08 PM, Chris Hallman wrote:

> Is it possible to send a F1 "character" over a telnet connection?  
> I've searched but I can't find a solution. I've tried SendKeys and  
> other methods, but I can't get it to work.
> import telnetlib
> pswd = "***"
> host = "***"
> tn = telnetlib.Telnet(host)
> tn.read_until("password:", 7)
> tn.write(pswd + "\n")
> tn.write(chr(27)) # ESC
> tn.write (chr(78)) # Shift N
> tn.write(chr(25)) # Down arrow
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

After all, it is not *that* inexpressible.
-H.H. The Dalai Lama

More information about the Tutor mailing list