为什么Mac连接新键盘时会要求你按下随机键?
Why do Macs ask you to press random keys when connecting a new keyboard?

原始链接: https://unsung.aresluna.org/why-do-macs-ask-you-to-press-random-keys-when-connecting-a-new-keyboard/

macOS 在连接新键盘时,有时会提示用户识别 Shift 键旁边的按键。这种看似奇怪的要求源于键盘无法以标准化方式向计算机传达其物理布局(ANSI 美国、ISO 欧洲或 JIS 日本)。 系统使用这些按键来区分布局——具体来说,每个 Shift 键旁边的按键是什么。虽然苹果自家的键盘可以识别自己,但许多第三方键盘不行,从而导致此提示。 对于美国/欧洲键盘,选择正确的布局主要影响外观,但对于日本键盘至关重要,因为它们在英文模式下具有不同的键帽标识,尽管向计算机发送相同的信号。选择不正确会导致按键输出错误的字符。 尽管界面有些笨拙,但这种方法巧妙地解决了一个复杂的问题,尤其是在许多键盘的厂商/型号识别不一致的情况下。这是一个“原始”但有效的解决方案,直到出现更强大的标准。

这个Hacker News讨论集中在Mac电脑连接新键盘时提示用户按下特定按键的原因。核心原因在于,Mac电脑不像Windows或Linux那样,不会默认“信任”键盘标签或维护一个全面的键盘布局数据库——后者通常会在设置过程中询问语言/地区,并默认匹配键盘。 用户指出,许多非苹果键盘并未专门针对Mac兼容性进行测试,因此需要通过按键识别来正确映射按键。虽然看似不便,但对于不熟悉键盘布局的用户来说,这种方法可能更友好,因为它允许Mac电脑*检测*布局,而不是要求用户*选择*布局。 有人建议采取更强大的安全措施,例如要求按键序列以防止“BadUSB”攻击,还有人建议改进USB HID协议,以便键盘可以直接识别其布局。一个主要的争论点是按键提示是否真的是“随机的”——有人认为它们是经过专门选择的,使其成为任意的而不是随机的。
相关文章

原文

You might have seen this, one of the strangest and most primitive experiences in macOS, where you’re asked to press keys next to left Shift and right Shift, whatever they might be.

Perhaps I can explain.

There are three main international keyboard layout variants in common use: American (ANSI, with a horizontal Enter), European (ISO, with a vertical Enter), and Japanese (JIS, with a square-ish Enter).

The shape of Enter and the shuffling of the surrounding keys is not the only difference. It’s also that the European layout has historically always had one more key – shoved in between Shift and Z – and the Japanese layout a few more.

But the main challenge is that a keyboard doesn’t have a way to tell the host computer what are its exact keys and where they’re located.

So, pressing the thing next to the left Shift can help Apple understand whether the keyboard is American or Japanese (always Z) or European (something else, but never Z). And pressing the thing next to the right Shift differentiates JIS (where it’s the _ key) from another keyboard (always /).

What I called “primitive” just above is actually clever in its approach. The legend of the key next to left Shift varies per locale (you can compare here), so the system can’t just tell you to press the < > key – and besides, asking the user to find a key that might not exist is a lot more stressful. And, identifying the keyboard by choosing a layout visually wouldn’t work either, since there are a million of layout variations – imagine having a split or a compact keyboard!

But it still is primitive, because it will still open up even if the keyboard you connect isn’t really a typing keyboard…

…or even if it doesn’t have any keys at all. (Some peripherals like credit card readers and two-factor dongles identify as keyboards as they transfer information by sending keystrokes.)

But: Why does it matter? What happens if you select the wrong layout or ignore the dialog?

If you mix up America and Europe, the difference should be largely cosmetic. After all, you still have to choose the keyboard language. People in, say, Germany will likely choose the appropriate locale, and the keys will do the right thing. However, also selecting the correct physical layout will properly display it in a few places, which can be helpful:

Japanese keyboards are more interesting, because they still have an English “mode” and the legends on a lot of the keys in that mode are different than on those on American and European keyboards – yet, the keys when pressed appear exactly the same (have the same “scan codes”) to the connected computer:

So knowing whether the keyboard is “US in the US” or “US in Japan” is important not just to place keys in the right position visually in a few places in macOS, but also for those keys to output what they actually show:

By the way, Apple’s own keyboards do not pop up this dialog. This is because while a keyboard can not do much when connected, it can at least send a vendor and model identification numbers, and Apple knows which of its keyboards sport what physical layout.

Why doesn’t macOS do that for third-party keyboards? They might, for some well-behaving ones; I don’t actually know. Unfortunately, the vendor/​model identification is a wild west and a lot of the keyboards I have identify simply as “unknown,” so building up an all-encompassing keyboard layout database is not really possible.

Either way, I mostly wanted to share why the dialog exists. Mind you, I don’t love it in that its language could be better and at one point it breaks a cardinal rule of reorienting options, which makes it hard to remember “oh yeah, it was the first scary setting that worked before.”

But overall, I thought it is a clever solution to a surprisingly hard problem. Sometimes primitive is better than nothing.

联系我们 contact @ memedata.com