Scancode

Last updated

A scancode (or scan code) is the data that most computer keyboards send to a computer to report which keys have been pressed. A number, or sequence of numbers, is assigned to each key on the keyboard.

Contents

Variants

Mapping key positions by row and column requires less complex computer hardware; therefore, in the past, using software or firmware to translate the scancodes to text characters was less expensive than wiring the keyboard by text character. [1] This cost difference is not as profound as it used to be. However, many types of computers still use their traditional scancodes to maintain backward compatibility.

Some keyboard standards include a scancode for each key being pressed and a different one for each key being released. In addition, many keyboard standards (for example, IBM PC compatible standards) allow the keyboard itself to generate "typematic" repeating keys by having the keyboard itself generate the pressed-key scancode repeatedly while the key is held down, with the release scancode sent once when the key is released.

Scancode sets

On some operating systems one may discover a key's downpress scancode by holding the key down while the computer is booting. With luck, the scancode (or some part of it) will be specified in the resulting "stuck key" error message. [Note: On Windows 7 only one byte of the scancode appears.]

PC compatibles

Scancodes on IBM PC compatible computer keyboards are sets of 1 to 3 bytes which are sent by the keyboard. Most character keys have a single byte scancode; keys that perform special functions have 2-byte or 3-byte scancodes, usually beginning with the byte (in hexadecimal) E0, E1, or E2. In addition, a few keys send longer scancodes, effectively emulating a series of keys to make it easier for different types of software to process.

PC keyboards since the PS/2 keyboard support up to three scancode sets. The most commonly encountered are the "XT" ("set 1") scancodes, based on the 83-key keyboard used by the IBM PC XT and earlier. These mostly consist of a single byte; the low 7 bits identify the key, 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 Return 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 backward compatibility, 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 motherboard 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.

A compliant PS/2 keyboard can be told to send scancodes in set 1, 2 or 3.

Example PC compatible (IBM PS/2) scancodes
keyset 1 (IBM PC XT)set 2 (IBM PC AT)set 3 (IBM 3270 PC)
pressreleasepressreleasepressrelease
A (simple letter)1E9E1CF0 1C1CF0 1C
↵ Enter (main keyboard)1C9C5AF0 5A5AF0 5A
↵ Enter (numeric keypad)E0 1CE0 9CE0 5AE0 F0 5A79F0 79
Left ⊞ Win (Windows key)E0 5BE0 DBE0 1FE0 F0 1F8BF0 8B
Right ⊞ WinE0 5CE0 DCE0 27E0 F0 278CF0 8C

USB

USB keyboards use a new set of scancodes, mostly specified in the USB standard. All computers that recognize USB keyboards recognize these new scancodes. [5]

See also

Related Research Articles

<span class="mw-page-title-main">BIOS</span> Firmware for hardware initialization and OS runtime services

In computing, BIOS is firmware used to provide runtime services for operating systems and programs and to perform hardware initialization during the booting process. The BIOS firmware comes pre-installed on an IBM PC or IBM PC compatible's system board and exists in some UEFI-based systems to maintain compatibility with operating systems that do not support UEFI native operation. The name originates from the Basic Input/Output System used in the CP/M operating system in 1975. The BIOS originally proprietary to the IBM PC has been reverse engineered by some companies looking to create compatible systems. The interface of that original system serves as a de facto standard.

The Break key of a computer keyboard refers to breaking a telegraph circuit and originated with 19th century practice. In modern usage, the key has no well-defined purpose, but while this is the case, it can be used by software for miscellaneous tasks, such as to switch between multiple login sessions, to terminate a program, or to interrupt a modem connection.

<span class="mw-page-title-main">IBM Personal Computer</span> Personal computer model released in 1981

The IBM Personal Computer is the first microcomputer released in the IBM PC model line and the basis for the IBM PC compatible de facto standard. Released on August 12, 1981, it was created by a team of engineers and designers directed by William C. Lowe and Philip Don Estridge in Boca Raton, Florida.

<span class="mw-page-title-main">IBM 3270</span> Family of block-oriented display terminals and printers made by IBM

The IBM 3270 is a family of block oriented display and printer computer terminals introduced by IBM in 1971 and normally used to communicate with IBM mainframes. The 3270 was the successor to the IBM 2260 display terminal. Due to the text color on the original models, these terminals are informally known as green screen terminals. Unlike a character-oriented terminal, the 3270 minimizes the number of I/O interrupts required by transferring large blocks of data known as data streams, and uses a high speed proprietary communications interface, using coaxial cable.

The keyboard for IBM PC-compatible computers is standardized. However, during the more than 30 years of PC architecture being frequently updated, many keyboard layout variations have been developed.

<span class="mw-page-title-main">Tandy 1000</span> IBM PC compatible home computer system

The Tandy 1000 is the first in a line of IBM PC compatible home computer systems produced by the Tandy Corporation for sale in its Radio Shack and Radio Shack Computer Center chains of stores. Introduced in 1984, the product line was aimed at providing affordable but capable systems for home computing or education, with some of its Tandy specific features like graphics, sound and joystick port making it more appealing for home use.

<span class="mw-page-title-main">IBM PC compatible</span> Computers similar to the IBM PC and its derivatives

IBM PC compatible computers are similar to the original IBM PC, XT, and AT, all from computer giant IBM, that are able to use the same software and expansion cards. Such computers were referred to as PC clones, IBM clones or IBM PC clones. The term "IBM PC compatible" is now a historical description only, since IBM no longer sells personal computers after it sold its personal computer division in 2005 to Chinese technology company Lenovo. The designation "PC", as used in much of personal computer history, has not meant "personal computer" generally, but rather an x86 computer capable of running the same software that a contemporary IBM PC could. The term was initially in contrast to the variety of home computer systems available in the early 1980s, such as the Apple II, TRS-80, and Commodore 64. Later, the term was primarily used in contrast to Apple's Macintosh computers.

<span class="mw-page-title-main">IBM PS/2</span> Second generation of personal computers by IBM

The Personal System/2 or PS/2 is IBM's second generation of personal computers. Released in 1987, it officially replaced the IBM PC, XT, AT, and PC Convertible in IBM's lineup. Many of the PS/2's innovations, such as the 16550 UART, 1440 KB 3.5-inch floppy disk format, 72-pin SIMMs, the PS/2 port, and the VGA video standard, went on to become standards in the broader PC market.

<span class="mw-page-title-main">Function key</span> Key on a computer or terminal keyboard

A function key is a key on a computer or terminal keyboard that can be programmed to cause the operating system or an application program to perform certain actions, a form of soft key. On some keyboards/computers, function keys may have default actions, accessible on power-on.

<span class="mw-page-title-main">IBM Personal Computer AT</span> IBM personal computer released in 1984

The IBM Personal Computer AT was released in 1984 as the fourth model in the IBM Personal Computer line, following the IBM PC/XT and its IBM Portable PC variant. It was designed around the Intel 80286 microprocessor.

<span class="mw-page-title-main">MPU-401</span> MIDI interface device

The MPU-401, where MPU stands for MIDI Processing Unit, is an important but now obsolete interface for connecting MIDI-equipped electronic music hardware to personal computers. It was designed by Roland Corporation, which also co-authored the MIDI standard.

<span class="mw-page-title-main">Kinesis (keyboard)</span>

Kinesis is a company based near Seattle that offers computer keyboards with ergonomic designs as alternatives to the traditional keyboard design. Most widely known among these are the contoured Advantage line, which features recessed keys in two bucket-like hollows to allow the user's fingers to reach keys with less effort. Moreover, the keys are laid out in perfect vertical rows to avoid the need for lateral movements during typing. In addition, the modifiers such as enter, alt, backspace, control, etc. are moved to a central location so they can be pressed with the stronger thumbs rather than the pinky fingers.

<span class="mw-page-title-main">Apple keyboards</span> External computer keyboards developed by Apple Inc.

Apple Inc. has designed and developed many external keyboard models for use with families of Apple computers, such as the Apple II, Mac, and iPad. The Magic Keyboard and Magic Keyboard with Numeric Keypad designed to be used via either Bluetooth and USB connectivity, and have integrated rechargeable batteries; The Smart Keyboard and Magic Keyboard accessories for iPads are designed to be directly attached to and powered by a host iPad. All current Apple keyboards utilize low-profile key designs, and common modifier keys.

<span class="mw-page-title-main">PS/2 port</span> 6-pin mini-DIN connector for connecting keyboards and mice to a PC compatible computer

The PS/2 port is a 6-pin mini-DIN connector used for connecting keyboards and mice to a PC compatible computer system. Its name comes from the IBM Personal System/2 series of personal computers, with which it was introduced in 1987. The PS/2 mouse connector generally replaced the older DE-9 RS-232 "serial mouse" connector, while the PS/2 keyboard connector replaced the larger 5-pin/180° DIN connector used in the IBM PC/AT design. The PS/2 keyboard port is electrically and logically identical to the IBM AT keyboard port, differing only in the type of electrical connector used. The PS/2 platform introduced a second port with the same design as the keyboard port for use to connect a mouse; thus the PS/2-style keyboard and mouse interfaces are electrically similar and employ the same communication protocol. However, unlike the otherwise similar Apple Desktop Bus connector used by Apple, a given system's keyboard and mouse port may not be interchangeable since the two devices use different sets of commands and the device drivers generally are hard-coded to communicate with each device at the address of the port that is conventionally assigned to that device.

Since the rise of the personal computer in the 1980s, IBM and other vendors have created PC-based IBM-compatible mainframes which are compatible with the larger IBM mainframe computers. For a period of time PC-based mainframe-compatible systems had a lower price and did not require as much electricity or floor space. However, they sacrificed performance and were not as dependable as mainframe-class hardware. These products have been popular with mainframe developers, in education and training settings, for very small companies with non-critical processing, and in certain disaster relief roles.

<span class="mw-page-title-main">IBM 3270 PC</span>

The IBM 3270 PC, released in October 1983, is an IBM PC XT containing additional hardware that, in combination with software, can emulate the behaviour of an IBM 3270 terminal. It can therefore be used both as a standalone computer, and as a terminal to a mainframe.

In computing, the USB human interface device class is a part of the USB specification for computer peripherals: it specifies a device class for human interface devices such as keyboards, mice, game controllers and alphanumeric display devices.

<span class="mw-page-title-main">Keyboard controller (computing)</span>

In computing, a keyboard controller is a device that interfaces a keyboard to a computer. Its main function is to inform the computer when a key is pressed or released. When data from the keyboard arrives, the controller raises an interrupt to allow the CPU to handle the input.

<span class="mw-page-title-main">IBM Personal Computer XT</span> Personal computer model released in 1983

The IBM Personal Computer XT is the second computer in the IBM Personal Computer line, released on March 8, 1983. Except for the addition of a built-in hard drive and extra expansion slots, it is very similar to the original IBM PC model 5150 from 1981.

<span class="mw-page-title-main">Power key</span> Computer key

The power key, or power button, is a key found on many computer keyboards during the 1980s and into the early 2000s. They were introduced on the first Apple Desktop Bus keyboards in the 1980s and have been a standard feature of many Macintosh keyboards since then. They are also found on an increasing number of Microsoft Windows keyboards, sometimes supplanted with additional keys for sleep. The power key is becoming increasingly rare, as most modern personal computers using USB allow the system to be started up by pressing any key on the keyboard.

References

  1. For example, the traditional 12-key numeric keypad is scanned as 3 columns by 4 rows, requiring a total of 7 connections. Scanning each key separately would require 12 connections.
  2. "Torvalds/Linux". GitHub . 18 February 2022.
  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.
  5. Microsoft Keyboard Scan Code Specification (Appendix C, "USB Keyboard/Keypad Page (0x07)"), Microsoft. Revision 1.3a, 2000-03-16, accessed 2018-10-13.