What’s a scan code?

Print anything with Printful



The process of getting a character from a keyboard to a screen involves scancodes, which vary by keyboard and language. Each key has two scancodes, one for pressing and one for releasing, and control characters also have codes. The computer examines the buffer and adds the character or attribute to the screen. Different keyboards have different scancodes to allow for different configurations and functions.

Very few people realize how much calculations, codes and processes are used just to get a character from a computer keyboard onto a screen. Part of this function is the scancode, which is a hexadecimal code which is the equivalent of the key pressed on the keyboard. There is a scancode for each key on the keyboard and there is another separate scancode for when the key is released. Keyboards for different character structures, such as Asian languages, will have different numbers of scancodes because the number of keys is different. When the button is pressed, the code is entered into a buffer area so that the computer can process and then add the character or recognize the key.

The whole keyboard process can be divided into several steps. When you press the key, the scancode enters the keyboard buffer. While in the buffer, an interrupt is used to tell the computer that something has been pressed on the keyboard. After realizing that a key has been pressed, the computer examines the buffer, checks the hexadecimal code, then adds the character or its attribute to the screen.

Both text and control characters have scan codes. Text keys are the most commonly used, containing letters, numbers, and symbols, but control characters are also often used. Control characters are those that do not create any symbols but do affect the document or character processing, such as the “shift” keys or the “enter” key.

Each key on the keyboard actually has two different scancodes, one for pressing and one for releasing. When a key is pressed, it supplies a scancode and the second code adds 128 to the hexadecimal value. This might seem pointless, because it seems rare for someone to hold down a key for several seconds, but this is often done with some control character such as the “shift” keys or the “delete” key.

The hexadecimal value for each key varies by keyboard. Each company has its own keyboard and while the configuration may be similar or even the same as others, the scancodes may be different. This is usually to allow the manufacturer to make keyboards with different key configurations or to add new functions to the keyboard, such as a “print” key.

Another factor in determining the hexadecimal value of each key is the language for which it is made. For example, Japanese and English keyboards have different numbers of keys because the number of characters used is different. Different English-speaking countries, such as the United States and England, also have different keyboards; most English keyboards have 102 keys and most US keyboards have 101.




Protect your devices with Threat Protection by NordVPN


Skip to content