使bash区分Ctrl-< letter>和Ctrl-Shift-< letter> [英] Make bash differentiate between Ctrl-<letter> and Ctrl-Shift-<letter>

查看:77
本文介绍了使bash区分Ctrl-< letter>和Ctrl-Shift-< letter>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法可以使bash为包含shift键的键组合发送不同的代码?例如(( Ctrl + V 向我显示) Ctrl + N Ctrl + Shift + N 被解释为相同的(^ N).还是有一个可以发挥作用的终端?还是可以修改我的bash以使其更改?

I was wondering whether there was any way of making bash send different codes for key combinations that include the shift key? for instance, (Ctrl+V shows me that) Ctrl+N and Ctrl+Shift+N are interpreted the same (^N). Or is there a terminal that can make the difference? Or can bash me modified so that it does?

推荐答案

终端不会直接与您的键盘进行交互;它与它接收到的字节流进行交互,这些字节流通常(但不一定)由键盘生成.对于可打印的ASCII值,该值与键盘上的键(或组合键)之间存在明显的对应关系. ASCII 97是 a ,ASCII 65是 Shift a ,依此类推.

A terminal doesn't interact directly with your keyboard; it interacts with a stream of bytes that it receives, which are usually (but not necessarily) generated by your keyboard. For the printable ASCII values, there is an obvious correspondence between the value and a key (or combination) on your keyboard. ASCII 97 is a, ASCII 65 is Shifta, and so on.

但是,存在32个非打印的 control 字符,从ASCII 0到ASCII 31,之所以被称为是因为它们旨在对终端进行 control .为了输入它们,添加了 Control ,以允许您与其他键结合使用以生成这些代码.使用了一个简单的方案.按下 Control - x 将生成与从 x 减去64相对应的控制代码.由于 @ 生成ASCII 64,因此 Control @ 生成ASCII0.对于 A _ (咨询您喜欢的ASCII参考以查看其余的对应关系).

However, there are the 32 non-printing control characters from ASCII 0 to ASCII 31, called which because they were intended to control a terminal. In order to enter them, the Control was added to allow you, in combination with the other keys, to generate these codes. A simple scheme was used. Pressing Control-x will generate the control code corresponding to subtracting 64 from x. Since @ generates ASCII 64, Control@ generates ASCII 0. The same mapping holds true for A through _ (consult your favorite ASCII reference to see the rest of the correspondences).

但是,是否需要使用Shift键才能通过ASCII 95生成ASCII 64取决于您的键盘.在我的美国键盘布局上,没有Shift键的情况下只能输入 [] . (请记住,这是我们在此处使用的大写字母字母ASCII范围,而不是小写字母.)因此,为了简化起见,我怀疑决定在其中忽略 Shift 确定使用 Control - x 发送哪个键码. (请注意,如果由于某种原因您的键盘上有一个键/Shift-键对生成的介于64和95之间的两个字符,则您的终端将需要为关联的控制字符定义一个备用映射.)

However, whether or not you need a shift key to generate ASCII 64 through ASCII 95 depends on your keyboard. On my US keyboard layout, only [ and ] can be typed without a shift key. (Remember, it's the uppercase-letter ASCII range we're using here, not the lowercase.) So to simplify, I suspect it was decided that Shift would be ignored in determining which keycode is sent with Control-x. (Note that if for some reason your keyboard had two of the characters between 64 and 95 generated by a key/Shift-key pair, your terminal would need to define an alternate mapping for the associated control character.)

所有这些都只是为了解释为什么 Control Shift - x Control - x 通常是相同的.显然,您的现代操作系统可以区分各种键盘组合.但是,在无数种可能性中,只有256种可以将唯一的值发送到终端.其余的必须复制其他一个或多个.为了有用,需要将它们配置为向终端发送一些多字节序列,通常以ASCII 27(ESC)开头.当终端接收到该字节时,它们会暂停片刻,以查看是否还有其他字节.功能键,方向键等键具有发送的相当标准的序列,终端以各种方式解释这些序列.其他键(例如您的示例中的 Control Shift n )没有约定的含义,因此终端仿真器必须分配一个.大多数仿真器都应允许您执行此操作,但是显然,它们的操作方式是特定于程序的.

All this is simply(?) to explain why ControlShift-x and Control-x are typically the same. Obviously, your modern operating system can distinguish all kinds of keyboard combinations. But out of the myriad possibilities, only 256 of them can send unique values to a terminal; the rest must necessarily duplicate one or more of the others. To be useful, they need to be configured to send some multiple-byte sequence to the terminal, typically beginning with ASCII 27 (ESC). When terminals receive that byte, they pause for a moment to see if any other bytes are coming after. Keys like function keys, arrow keys, etc. have fairly standard sequences they send, which the terminal interprets in various ways. Other keys (like ControlShiftn in your example) have no agreed-upon meaning, and so your terminal emulator must assign one. Most emulators should allow you to do this, but how they do so is, obviously, program-specific.

这篇关于使bash区分Ctrl-< letter>和Ctrl-Shift-< letter>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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