键盘扫描码(英语:scancodescan code)是电脑键盘计算机发送的一项数据,用于告知计算机哪些键被按下,这项数据对于绝大多数现代电脑键盘而言,遵循相同或几乎相似的逻辑。

变种

编辑

以行、列映射定位位置(也就是二维数组形式)可以使键盘不必使用复杂控制芯片,因此在过去,使用软件固件翻译扫描码为文本字符比连接文本字符键盘更便宜。[1]这项成本差异已随计算机芯片制造业发展而不再明显。但目前,仍有许多种计算机在使用传统的扫描码以维护向下兼容

部分键盘标准中,每个按键的按下与松开的扫描码不相同。此外,许多键盘标准(例如IBM PC兼容机)允许键盘本身发送“typematic”表示键盘按键被持续按住,键盘本身在重复生成扫描码。

扫描码集

编辑

PC兼容机

编辑

IBM PC兼容机键盘上的扫描码是由键盘发送的1至3个字节为一组。大多数字符键具有单字节扫描码,执行特殊功能的按键用2字节或3字节扫描码,通常以下列字节开头(十六进制): E0E1E2。此外,有几个按键发送更长的扫描码以有效方针一组按键,以便于操作某些软件。

PS/2接口起的PC键盘支持最多三组扫描码集。最常遇到的是“XT”扫描码,它基于IBM PC XT及更早的计算机使用的83按键键盘。其大部分由单字节组成,低7位标识按键,

已隐藏部分未翻译内容,欢迎参与翻译
and the most significant bit is clear for a key press or set for a key release. Some additional keys have an E0 (or rarely, E1 or E2) prefix. These were initially assigned so that ignoring the E0 prefix (which is in the key-up range and thus would have no effect on an operating system that did not understand them) would produce reasonable results. For example the numeric keypad's Enter key produces a scancode of E0 1C, which corresponds to the regular Enter key's scancode of 1C.

The IBM 3270 PC introduced its own set of scancodes ("set 3"), with a different key numbering and where a key release is indicated by an F0 prefix. For 向下兼容, the 3270 PC translated these to XT (set 1) scancodes using an add-on card and a BIOS extension. This set is used by Linux by default when it detects a PS/2 keyboard that can properly support scan code set 3.[2]

The IBM PC AT introduced the "AT" ("set 2") scancodes. On the 84-key AT keyboard these were largely a subset of set 3, with some differences caused by the revised layout (for example, the position and scancodes of the function keys changed). Keys added since the PC AT often have different scancodes in set 2 and set 3, and in set 2 frequently have an E0 or E1 prefix. Again, key release is indicated by an F0 prefix.

For computers since the IBM PC AT, the keyboard controller on the 主板 translates AT (set 2) scancodes into XT (set 1) scancodes in so called translation mode.[3] This translation can be disabled in pass-through-mode, allowing the raw scancodes to be seen.[4] Therefore, whether a software developer will encounter AT scancodes or XT scancodes on a modern PC-compatible depends on how the keyboard is being accessed.

PS/2兼容键盘会被告知所要发送的是扫描码集合1、2或3。

PC兼容(IBM PS/2)扫描码
按键 集合1(IBM PC XT 集合2(IBM PC AT 集合3(IBM 3270 PC英语IBM 3270 PC
按下 松开 按下 松开 按下 松开
A(普通字符) 1E 9E 1C F0 1C 1C F0 1C
Return / Enter(主键盘) 1C 9C 5A F0 5A 5A F0 5A
Enter数字键盘 E0 1C E0 9C E0 5A E0 F0 5A 79 F0 79
Windows键 E0 5B E0 DB E0 1F E0 F0 1F 8B F0 8B
右Windows键 E0 5C E0 DC E0 27 E0 F0 27 8C F0 8C

USB键盘使用一组新的扫描码集合,大部分在USB标准中指定。所有能识别USB键盘的计算机都能识别这组扫描码。

参见

编辑

参考资料

编辑
  1. ^ 例如,传统的12键数字键盘扫描为3列乘4行,共需要7个连接点。而单独连接每个键需要12个连接点。
  2. ^ 存档副本. [2017-09-25]. (原始内容存档于2019-07-10). 
  3. ^ Keyboard scancodes页面存档备份,存于互联网档案馆) (section 10, "Keyboard internal scancodes"页面存档备份,存于互联网档案馆)), Andries Brouwer. Version 1.2e, 2004-05-20, accessed 2006-11-15.
  4. ^ Keyboard scancodes页面存档备份,存于互联网档案馆) (section 11, "The AT keyboard controller"页面存档备份,存于互联网档案馆)), Andries Brouwer. Version 1.2g, 2009-07-07, accessed 2010-07-18.

外部链接

编辑