如何在发送到 SSH shell 的字符串中编码返回/输入按键? [英] How is a return / enter keypress encoded in a string sent to a SSH shell?

查看:41
本文介绍了如何在发送到 SSH shell 的字符串中编码返回/输入按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为键盘上没有返回键的特殊设备制作 SSH 客户端,我的问题是如何将字符串中的返回键编码发送到 shell?只是'\n'吗?

I am making a SSH client for a special device which does not have a return key on it's keyboard, my question is how is the return key encoded in the string sent to the shell? is it just '\n'?

推荐答案

然后 Enter 键发送字符 13 = \015 = 0x0d = \r = ^M = CR (回车).您可以通过在终端中输入 Ctrl+V 然后 Enter 来观察:Ctrl+V 告诉 shell 按字面意思插入下一个字符,而不是将其解释为命令.

Then Enter key sends the character 13 = \015 = 0x0d = \r = ^M = CR (carriage return). You can observe that by typing Ctrl+V then Enter in a terminal: Ctrl+V tells the shell to insert the next character literally instead of interpreting it as a command.

您可以在 stty 设置,但并非所有应用程序都会注意到.最好使用标准字符.

You can select a different end-of-line character in stty settings, but not all applications will notice. It's better to use the standard character.

由于历史原因,键盘上 Enter 键发送的字符与文本文件中指示行尾的字符不同:行尾字符为 10 =\012 = 0x0a = \n = ^J = LF(换行).

For historical reasons, the character sent by the Enter key on keyboards is not the same character that indicates the end of a line in a text file: the end-of-line character is 10 = \012 = 0x0a = \n = ^J = LF (line feed).

这篇关于如何在发送到 SSH shell 的字符串中编码返回/输入按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆