问题
I am programming a Java connection to a server using the Apache commons telnet library. I have modified the example code at http://www.java2s.com/Code/Java/Network-Protocol/ExampleofuseofTelnetClient.htm to connect to our server and preform tests. Everything seems to work fine but I cannot figure out how to send function key presses over telnet.
After using a sniffer with our IBM 3151 emulator for the function key 'F9' I got the value: '/033i/r', but simply just typing this in does not work. I figure it is just sending those text characters when I simply type them.
I'd imagine that I just missing something simple but I cannot seem to find any information after searching for a few hours.
回答1:
After searching for a bit longer I found that I had to send the ASCII hex characters in a byte array to the outputStream of the telnet session that corresponded to the terminal type I was using.
Thus to send '/033i/r' which is the code for the function key: 'F9', I created the following byte array:
byte[] toSend = new byte[] { (byte)0x1b, (byte)0x69, (byte)0x0d } ;
So you need to know which terminal emulation you are using for your telnet connection, and what the function keys map too.
来源:https://stackoverflow.com/questions/35181877/java-telnet-apache-commons-how-to-send-functions-keys