This page has a list of keystrokes and their corresponding scan codes. I'm confused by this. I noticed each scan code starts with a NUL character. Does this mean when the input stream receives a NUL character, that means to interpret the next byte as a scan code? Also, I'm curious as to what platform uses these, because they don't seem to be used on Unix systems. On my system, if I want to write a program that recognizes, say, the arrow keys, I just use the three-byte UTF-8 codes for those keys.
-
This is a hardware thing, not an "IBM" thing. Arrow keys and UTF-8 have nothing in common, so I'm not sure what you're suggesting. What input stream? What program? What operating system? What hardware? – tadman Mar 20 '18 at 20:19
-
Other tables don't show that leading zero - http://www.philipstorr.id.au/pcbook/book3/scancode.htm for example – Joe Mar 20 '18 at 20:22
1 Answers
A scan code is a value sent by the microprocessor in the keyboard to the computer (there is a small computer in your keyboard). It has nothing to do with ASCII. It is a two-byte code, that the system then converts to ASCII or whatever it wants to do. It is independent of ASCII.
This is how special keyboards such as gaming, etc can have one-shot keys and how the computer can adjust the brightness/contrast, volumes etc with Fn+special key, etc.
When you press the Caps-Lock, for example, the Scan-Code is sent to the computer and ONLY if the computer acknowledges it will the MPU in the keyboard switch on the Caps-Lock light (LED) (Cool, what?)
During the home computer craze in the early 1980s, IBM's main advantage was that they designed a computer that could be expanded (an excellent design that prevails to date, as you can see - opinion and British Innovation Awards). believe it or not, this was one of the questions asked in the final exam of my Diploma in Microprocessor design technology I had to do for my 'qualifications' in 1988.
You can try out entering scan codes directly on your keyboard by:
- Fire up notepad or a text editor (vi, etc).
- Press Alt, while Alt is pressed type 0,6,5 (without the commas) on the numeric keypad. The letter A will be displayed. Do Alt + 008 and the A will be erased (backspace).
Trust this helps.

- 382
- 2
- 11
-
Those "scan codes" you mention at the end are actually ASCII (^H for backspace is ASCII 8; A is ASCII 65.) The Alt + numerics map to decimal codepoints, not scan codes. – Matt Gibson Mar 20 '18 at 20:37
-
-
Pick another ASCII character and type its decimal code value using the alt+numeric keypad method. Still coincidence? – Matt Gibson Mar 20 '18 at 20:47
-
IBM mapped the ASCII scan codes 1 to 1 :) I was just giving the person asking the question a method to try it out. If you program in MS-DOS/Assembler/BIOS (which I have) you also get the '00'. The ENTIRE ASCII table is mapped one-to-one, but the IBM scan codes are NOT ASCII. ASCII is 7 BIT, the Scan Codes are 16bit. – Mr. de Silva Mar 20 '18 at 20:58