简体   繁体   中英

escape sequence for all the keyboard keys in python

i am using telnetlib in python... i have used '\\r' for enter key,'\\t' for TAB. as same as this scenario i want the char sequence for SHIFT,PAGE UP,PAGE DOWN,F1,F2...F12. pleas help me regarding this issue as i have to use all this keyboard keys in my code.

import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.write("ls\n")
tn.write("exit\n")
tn.write("\r") #this is for enter
tn.write("\t") # this is for tab

#what should be here to other keys..pls

print tn.read_all()

您可以随时使用thistelnet客户端: https ://www.redhat.com/archives/redhat-list/2000-August/msg00070.html

Unfortunately not all key-presses result in one or more bytes being sent over the wire. This is really about terminal emulation, since control keys are "meant" to be interpreted by the terminal device (or emulator).

Different terminal types define different keys and map them to different byte values in the stream. For example, some terminals have F11 and F12, and some don't. Some define Ctrl+F keys, Shift+F keys, Alt+F keys, Command+F keys; others don't. And different terminals map these keys to completely different byte sequences over the wire. The issue is the same when it comes to arrow keys and cursor-mode keys like insert.

You may find that certain keys are trapped by the client and not transmitted at all, or that non-keyboard events (such as resizing the terminal window with the mouse) transmit terminal escape sequences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM