Scan code

from Wikipedia, the free encyclopedia

In computer technology, a scan code is a number that is sent to a computer's keyboard when a key is pressed or released.

PC / XT keyboard

In 1981, IBM introduced an 83-key keyboard along with the first IBM PC . Since this was retained unchanged in the IBM PC / XT , which was released in 1983 , it is known today as the XT keyboard .

Earlier computer keyboards often sent ASCII or codes from another character set standard directly to the computer. In order not to have to generate different codes for every country-specific keyboard variant in the IBM PC planned for sale in many countries , each key was assigned a number, the so-called scan code . An ASCII code was then assigned to the scan code by the keyboard driver in the computer . For the scan code, the keys were simply numbered in rows from left to right according to their position on the keyboard, in contrast to the ASCII code, which follows the alphabetical order.

A standard keyboard driver for the US assignment was integrated in the BIOS of every PC ; country-specific assignments were made by a software keyboard driver that was loaded as a TSR program when the system was started. Under MS-DOS this program is called "KEYB.COM", other operating systems often use the same name.

Thus, IBM only had to install differently printed keycaps for PC keyboards for sales in different countries, while the keyboard electronics could remain the same and nothing at all had to be changed on the computer itself.

The XT keyboard had a block of 10 function keys on the left and the alphanumeric keys with an attached number block on the right. LEDs for signaling the current status and a separate arrow key block did not yet exist. Communication took place exclusively from the keyboard to the PC, so the PC could not yet send any commands to the keyboard. The basic structure of the serial interface is described under PS / 2 interface ; The typical connector for PC and AT keyboards, however, was for many years a 5-pin DIN connector , which was known in Germany as a connector for LF signals ("transfer cable").

PC / AT keyboard

The logical further development was the 84-key AT keyboard introduced in 1984 with the IBM PC / AT (separate function keys and 10 -key pad). The physical interface was retained here, but the signaling was completely redesigned. The communication between computer and keyboard was now bidirectional , recognizable, for example, from the fact that the computer could switch the status LEDs under program control. The transmitted codes were completely different from those of the XT. A small one-chip computer ( Intel 8042 ) on the motherboard of the computer, somewhat ambiguously called "keyboard BIOS", converted the actually transmitted codes to compatible values. In terms of software, an AT keyboard (with its upstream “keyboard BIOS”) looked very similar to an XT keyboard; in this way the important compatibility of the computers could be maintained. The implementation of the codes could be switched off, and IBM expected that it would normally be switched off as soon as a more modern operating system became available; in practice, however, MS-DOS or PC-DOS was still used almost everywhere and the implementation was practically always switched on.

Converting an XT to an AT usually required replacing the keyboard; But there were also keyboards that had a switch on the underside or that could switch automatically to suit.

MF2 keyboard

German MF2 keyboard with 105 keys; the numbers given are key numbers, not scan codes

The next generation change took place in 1986 when IBM brought out the 101-key MF2 keyboard ( multi-functional ) for the US market. The country-specific 102-key MF2 keyboard was defined in the same way. Ultimately, all of today's standard extensions, such as the 104/105 key Windows keyboard, are based on these two keyboard layouts.

The MF2 keyboard used the same interface and signaling as the previous PC / AT keyboard. From 1987 the connector for the IBM PS / 2 computer was replaced by a smaller version, but the electrical signals remained the same.

The arrangement of the keys has been changed so that the function keys, the number of which has been increased by two at the same time, are now above the alphanumeric keys. The numeric keypad and special keys for moving the cursor have been optically separated.

Basically, when a key is pressed, the corresponding scan code of the key is sent. If you press the button longer, the same scan code is sent repeatedly and when you release a break code $ F0 is added to the scan code .

However, the “keyboard BIOS” continues to implement these values. After this conversion, the top bit is usually 0 for make code , but 1 for break code .

Example: The space bar has the make code $ 39 and the break code $ B9 after implementation .

In order to be compatible with the XT keyboard with an MF2 keyboard, the keys of the new cursor block (after conversion) were given the same code with a special code $ E0 or $ E1 to distinguish them. Old software usually ignored the unknown code $ E0 or $ E1 and only processed the following code, which was the same as for the corresponding key of the old combined digit / cursor block. New software, on the other hand, could recognize the code $ E0 or $ E1 if necessary and then knew that a key of the new cursor block and not one of the combined digits / cursor block had been pressed.

The American MF2 keyboard has 101 keys; the country-specific 102 keys. On German keyboards, the additional key has the three characters "<", ">" and "|", the left shift key has been reduced for this.

Keyboard shortcuts

  • If the keyboard is reset (PC sends Reset = $ FF ), it answers with Bat = $ AA if the Basic Assurance Test is successful
  • If the keyboard is reset and there is an error, for example a key jams, it responds with BatE1 = $ FC or BatE2 = $ FD .
  • The communication test is carried out by the PC with echo = $ EE and the keyboard also replies with echo = $ EE .
  • In general, all keyboard commands are confirmed by the keyboard with Acknowledge Ack = $ FA . If there is something wrong with the data, there is a misunderstanding Misu = $ FE .
  • If the keyboard is asked for its type with Read ID = $ F2 , an MF2 keyboard answers with 2 bytes ID1 = $ AB and ID2 = $ 83 . For reasons of compatibility, this was never changed for later keyboards, so that in practice the type cannot be queried using the software (except for USB keyboards, see below).
  • If the keyboard buffer is full, the keyboard responds with Full = $ FF .
  • The command Set LED = $ ED from the PC followed by a byte controls the LEDs (Bit 0..2 = ScrlLock, NumLock, CapsLock; Bit 3..7 = 0).
  • Set code set = $ F0 coming from the PC followed by a byte selects code set 1..3.
  • Set code set = $ F0 followed by 0 coming from the PC asks which code set is active.
  • Command Set Speed ​​= $ F3 from the PC followed by a byte controls the delay time between pressing the key and starting the automatic key repetition (bit 5, 6) and the repetition rate (bit 0..4).
  • Enable = $ F4 coming from the PC activates the scanning process and Disable = $ F5 deactivates the scanning process so that no more keystrokes are recognized.
  • Set Default = $ F6 coming from the PC sets everything to standard values.
  • Resend = $ FE coming from the PC prompts the keyboard to repeat the last response code. Resend = $ FE coming from the keyboard inversely prompts the computer to repeat. These codes are sent if parity errors or incomplete bytes are received due to a line fault .

Code sets

The code table of the PC keyboard is complex; within the MFM keyboard itself there are three tables with scan codes, which can be selected by sending command codes to the keyboard.

  • Scan code set 1 (essentially corresponds to the XT keyboard)
  • Scan code set 2 (essentially corresponds to the AT keyboard, today's standard)
  • Scancode-Set 3 (new, more logically structured code set of the MF2 keyboard, but which never caught on)

In addition, the conversion of keyboard codes can be switched on and off using the "Keyboard BIOS" located in the computer housing (today's standard: switched on); This results in a total of six possible code variants from the perspective of the firmware and software that ultimately receive the codes.

Keyboards from other manufacturers than IBM have sometimes failed to implement scan code sets 1 and 3 or implemented them incorrectly. Likewise, the deactivation of the scan code conversion does not work correctly on some mainboards. The existing PC emulators do not implement these variants either. For this reason, all of today's PC operating systems only use Scancode Set 2 with conversion activated. The controller in the keyboard transfers the codes to the "keyboard BIOS" in the PC with scan code set 2, and this then converts them to scan code set 1. The software therefore usually only gets the oldest version, set 1, on all PCs Face - on the original PC and on XTs directly, on ATs and all newer PCs via implementation.

USB keyboards

USB keyboards use a new set of scan codes unrelated to the various older systems; the corresponding drivers of new operating systems can process these codes. For use with boot loaders and older operating systems, their scan codes are mapped to the old scan codes by software from the computer's BIOS . Only the scan code set 2 with activated conversion is emulated. Some BIOSes do this conversion incompletely. B. sometimes the AltGr key is not differentiated from the Alt key, which is problematic for German keyboards.

The scan codes for USB keyboards are uniform across all architecture. USB keyboards for the Apple Macintosh series therefore use the same scan codes as PC USB keyboards.

Web links