鍵盤掃描碼

鍵盤掃描碼(英語: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標準中指定。所有能識別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.

外部連結