简体   繁体   English

python中所有键盘键的转义序列

[英]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. 我在python中使用telnetlib ...我已经用'\\ r'作为回车键,'\\ t'是TAB。 as same as this scenario i want the char sequence for SHIFT,PAGE UP,PAGE DOWN,F1,F2...F12. 与此场景相同,我希望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. 例如,某些终端具有F11和F12,而有些则没有。 Some define Ctrl+F keys, Shift+F keys, Alt+F keys, Command+F keys; 有些定义了Ctrl + F键,Shift + F键,Alt + F键,Command + F键; 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. 您可能会发现某些键被客户端捕获而根本没有传输,或者非键盘事件(例如使用鼠标调整终端窗口的大小)会传输终端转义序列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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