Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  Each time you press or release one of the keys on the keyboard, the
  keyboard circuits transmit a sequence of one or more 8-bit numbers through
  the connector cable to the computer. This sequence, called a scan code,
  uniquely identifies the key you pressed. The keyboard produces different
  scan codes, depending on whether the key was pressed or released. Whenever
  you press a key, the scan-code byte contains a number ranging from 01H
  through 58H. When you release the key, the keyboard generates a scan code
  80H higher than the keystroke scan code by setting bit 7 of the scan-code
  byte to 1. For example, when you press the letter Z, the keyboard
  generates a scan code of 2CH; when you release it, the keyboard generates
  a scan code of ACH (2CH + 80H). The keyboard diagrams in Figures 6-1,
  6-2, and 6-3 show the standard keyboard keys and their associated scan
  codes.

  +------------------------------------------------------------------------+
  | Figure 6-1 can be found on p.128 of the printed version of the book.   |
  +------------------------------------------------------------------------+

  Figure 6-1.  Scan codes for the 83-key keyboard (PC, PC/XT). Scan-code
  values are in hex.

  +------------------------------------------------------------------------+
  | Figure 6-2 can be found on p.128 of the printed version of the book.   |
  +------------------------------------------------------------------------+

  Figure 6-2.  Scan codes for the 84-key keyboard (PC/AT). Scan-code values
  are in hex.

  +------------------------------------------------------------------------+
  | Figure 6-3 can be found on p.129 of the printed version of the book.   |
  +------------------------------------------------------------------------+

  Figure 6-3.  Scan codes for the 101/102-key keyboard (PC/AT and PS/2).
  Scan-code values are in hex.

  If you compare the scan codes for the 83-, 84-, and 101/102-key keyboards,
  you'll see that a key generates the same scan code regardless of its
  location on the keyboard. For example, the Esc key has a scan code of 01H,
  whether it's next to the 1 key, next to the Num Lock key, or by itself in
  the upper-left corner. (The 101/102-key keyboard can actually generate
  different scan codes, but the start-up ROM BIOS suppresses this by
  configuring the keyboard to be compatible with the 83-key keyboard.)

  The 101/102-key layout contains duplicate shift and control keys that
  don't exist on the other keyboards. The 101/102-key keyboard distinguishes
  between duplicate keys by transmitting multiple-byte scan codes. For
  example, the two Alt shift keys have different scan codes: The left Alt
  key has a scan code of 38H, and the right Alt key has a 2-byte scan code,
  E0H 38H.

  --------------------------------------------------------------------------
  NOTE:
    The multiple-byte scan codes for shift and control keys can vary
    depending on whether one of the shift keys (Ctrl, Alt, Shift), Num Lock,
    or Caps Lock is pressed at the same time. See IBM's PS/2 technical
    reference manuals for details.
  --------------------------------------------------------------------------

  The 101/102-key keyboard also assigns special scan codes to certain
  keystroke combinations. The Alt-Sys Req combination is intended to be the
  same as the Sys Req key on the 84-key layout, so the 101/102-key keyboard
  transmits the same scan code, 54H. Because the Print Screen key has the
  same function as the Shift-PrtSc combination in the other keyboard
  layouts, the 101/102-key keyboard transmits a Shift key scan code (E0H
  2AH) followed by the PrtSc scan code (E0H 37H). The Pause key's scan code,
  E1H 1DH 45H, resembles the scan-code sequence for the Ctrl-Num Lock
  combination, but when you press Ctrl-Pause (that is, Ctrl-Break), the
  keyboard transmits E0H 46H E0H C6H, which is derived from the scan code
  for the Scroll Lock (Break) key on the 83- and 84-key keyboards. Figure
  6-4 lists these keystroke combinations and their associated codes.

  101/102-key Keyboard     84-key Keyboard         Scan Code
  Keystroke Combination    Equivalent              Transmitted
  --------------------------------------------------------------------------
  Alt-Sys Req              Sys Req                 54H
  Print Screen             Shift-Print Screen      E0H 2AH
                                                   E0H 37H
  Ctrl-Break               Ctrl-Break              E0H 46H E0H C6H
  --------------------------------------------------------------------------

  Figure 6-4.  Scan codes for special keystroke combinations on the
  101/102-key keyboard.

  --------------------------------------------------------------------------
  NOTE:
    The "compact" keyboard available for the PS/2 Model 25 is really a
    101/102-key keyboard in disguise. The numeric keypad is mapped to a
    group of 14 keys on the main keyboard, and the Num Lock key is the shift
    state of the Scroll Lock key. However, keyboard scan codes and ROM BIOS
    processing are the same for the compact version as for the full-size
    101/102-key keyboard.
  --------------------------------------------------------------------------

  Any program that processes keyboard scan codes must be aware of which
  machine it's running on and which keyboard is in use. Fortunately, few
  programs need to respond directly to keyboard scan codes--the ROM BIOS
  keyboard service routines translate scan codes into meaningful information
  that a program can use. The following sections describe this translation
  process more fully.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson