4.2.2 Keyboard Control

A program opens a keyboard by using Open File with Handle (Interrupt 21h Function 3Dh). This function takes the device name CON and the read-only access parameter and returns a handle for the keyboard. The program uses the handle with Read File or Device (Interrupt 21h Function 3Fh) to read from the keyboard.

In ASCII mode, MS-DOS reads characters from the keyboard and copies the characters to standard output. It checks for control characters as it reads and, if it finds one, carries out the corresponding action. It also checks for the BACKSPACE key and function keys (such as F1, F2, and F3) and carries out the same editing actions for these keys as it does for COMMAND.COM. It removes the editing-key codes from the input as it carries out the editing action. MS-DOS continues to read characters until it has read the number of characters specified by the program or until the user presses CTRL+Z or ENTER. It translates the ENTER key into a carriage return-linefeed character pair.

In binary mode, MS-DOS reads the exact number of characters requested by the program. It does not copy characters to the screen, nor does it process control characters and editing keys. Instead, it reads all characters as input.