ArticleslgStudy

computer science

Scancode

Scancode is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Scancode rather than just read about it. In short: Broadly speaking, a scancode (or scan code) is either a number or bit array that is used by a keyboard protocol to uniquely identify a keyboard key. Keyboards normally send scancodes to the computer to update the computer's internal keyboard state (which tracks what keys are being held down).

Key takeaways

  • Scancode belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Scancode to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Scancode from memory before moving on to harder problems.

Reference excerpt

Broadly speaking, a scancode (or scan code) is either a number or bit array that is used by a keyboard protocol to uniquely identify a keyboard key. Keyboards normally send scancodes to the computer to update the computer's internal keyboard state (which tracks what keys are being held down). The exact mechanism how, when and what scancodes are sent depends on the protocol. A keyboard protocol may use other means to update the computer's internal keyboard state, such as sending a bitmap that encodes the state of keys (pressed/released). This is partially the case for a keyboard using the HID protocol when the Boot Protocol is selected. It will send the states of modifier keys encoded in a bitmap (where each bit represents a key state) alongside a scancode array of pressed keys (excluding modifier keys).

History 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. 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.

PC compatibles IBM PC compatible computer keyboards send a scancode when a key is pressed and released. When a key is pressed its so called "make" scancode is send which differs from its so called "break" scancode that is send when the key is released. The IBM PC compatible standard also allows keyboards to generate "typematic" repeating keys by having the keyboard itself generate the make scancode repeatedly while a key is held down. Most character keys have a single byte make 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 which emulate 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. A PS/2 compatible keyboard can be told to send scancodes in set 1, 2 or 3, although it is keyboard-dependent which scancode sets are supported by the keyboard. 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 (make scancode) or set for a key release (break scancode). 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. 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. This translation can be disabled in pass-through-mode, allowing the raw scancodes to be seen. Therefore, whether a software developer will encounter set 2 scancodes or set 1 scancodes on a modern PC-compatible depends on how the keyboard is being accessed. If linux detects a translation from set 2 to set 1 by the keyboard controller it will use set 1, otherwise it will almost certainly use set 2.

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.

Further information 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.] A virtual keyboard does not input scancodes but Unicode characters.

See also Dead key Meta key Keyboard layout

Notes

References

External links Keyboard scancodes: written by Andries Brouwer Interfacing the AT Keyboard: Detailed information on keyboard scancodes from beyondlogic.org

Worked examples

Example 1 — a first encounter with Scancode

Start with the simplest possible case. Write down what Scancode claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Scancode before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Scancode ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Scancode

In research
Scancode appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Scancode in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Scancode is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer keyboards, Data transmission, Encodings, so understanding it makes those chapters shorter.
In everyday life
Look for Scancode outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Scancode in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Scancode means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Scancode out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Scancode in simple terms?

Broadly speaking, a scancode (or scan code) is either a number or bit array that is used by a keyboard protocol to uniquely identify a keyboard key. Keyboards normally send scancodes to the computer to update the computer's internal keyboard state (which tracks what keys are being held down).

Why does Scancode matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Scancode?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Scancode.

Tags

  • Computer keyboards
  • Data transmission
  • Encodings

Keep exploring