新起点
键盘扫描码
2020-12-22 06:52:27

键盘扫描码(英语:scancode或scan code)是绝大多数电脑键盘向计算机发送的一项数据,用以报告哪些键被按下。它使用一个数字或数字序列来表示分配到键盘上的每个按键。

以行、列映射按键位置能减少复杂硬件的使用;因此在过去,使用软件或固件翻译扫描码为文本字符比连接文本字符键盘更便宜。这项成本差异已随时间演变而不再明显。但目前,仍有许多种计算机在使用传统的扫描码以维护向下兼容。

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

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

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

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.

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.

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

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

网站公告: