Classic Computer Magazine Archive COMPUTE! ISSUE 74 / JULY 1986 / PAGE 76

IBM Keyboard Customizer

David Engebretsen

This tutorial for the IBM PC/PCjr explains how to customize your computer's keyboard with simple DOS 2.0 or higher commands. Besides reassigning key definitions to your own personal taste, you can create keyboard macros, define as many as 40 function keys and choose new screen modes and color combinations.

Have you ever wished you could change a key on the keyboard into another key, or make a single keystroke spell out an entire phrase? Would you like to move the colon and the semicolon keys, or put the Return key in a more convenient position? It is quite possible do to all this and more with a few simple commands from DOS. You can even create up to 40 different function keys which can be used to print a variety of command words or phrases of any length. With a little more work, you can even change your standard QWERTY keyboard into the efficient Dvorak format which can improve typing speed dramatically.

All this is made possible with the extended screen and keyboard control offered by DOS 2.0 and higher. Though the DOS manual devotes only one page to this subject, the process is not complicated. Let's look first at how to switch key assignments. Then we'll explore how to perform related tasks such as setting the screen mode, changing the background and foreground colors, and positioning the cursor.


It is suprisingly easy to reassign any key or keys to a location that suits your own personal needs. The first step is to create a CONFIG.SYS file that installs an extended screen and keyboard control device driver when you boot the system. This can be done with the EDLIN system editor included on your DOS disk. From the DOS command prompt (>) simply type EDLIN CONFIG.SYS and press Return. The drive will whir as it opens a new file; after a few moments your screen should look something like this:

New file

Type the following lines, pressing Return at the end of each line:


Press Ctrl-Break, then type the number 3 and press Return. At this point you have created a configuration file that runs automatically whenever you boot the computer. The result is that the computer is then made ready to accept some new key assignments.

Reassigning Key Definitions

The next step is to do the actual key switching. Since this can involve some odd character sequences, it's easiest to do this from within a BASIC program that stores the needed data in a text file on disk. Here is a program that demonstrates the technique. We'll use it to create a file that changes the uppercase Q to an uppercase D.

DN 10 A$=CHR$(27) + "[" + CHR$(3
      4) + "Q" + CHR$(34) + ";"
      + CHR$(34) + "D" + CHR$(34
      ) + "p"
      AS #1
GM 40 CLOSE #1

Save this program as REASSIGN.BAS and run it. REASSIGN.BAS creates a text file that contains the following character sequence:


CHR$(27) is the ASCII code for the ESC character; this is the control code which changes the uppercase Q into an uppercase D. To implement this change, insert the disk containing your new CONFIG.SYS file, then reboot by pressing Ctrl-Alt-Del simultaneously. This enables the ANSI device driver which in turn allows the keyboard to be redefined.

After answering the time and date prompts, type TYPE KEY.TXT at the DOS prompt and press Return. This action enters the special control characters into the computer's memory. Now whenever you type an uppercase Q, the system substitutes an uppercase D.

Keyboard Macros

The same technique can be used to create a keyboard macro--a key that produces a multicharacter word or phrase with just one keystroke. To illustrate, let's redefine uppercase Q so that it prints the phrase The Phrase whenever it's pressed. Reenter BASIC and load the REASSIGN.BAS program again, then replace line 10 as shown here:

EP 10 A$=CHR$(27)+"["+CHR$(34)+"
      The Phrase"+CHR$(34)+"p"

Now run the program again. This creates a text file that contains these characters:

ESC ["Q";"The Phrase"p

Type SYSTEM to go back to DOS, then type the KEY.TXT file again. Now whenever you press Q the computer prints The Phrase on the screen.

When creating the KEY.TXT file, it is also acceptable to substitute an ASCII code for the character. For example, say that you want to change uppercase Q back to uppercase 0. Go back to BASIC again and change line 10 as shown here. Note that instead of 0 we are using 68, the ASCII code for 0:

PM 10 A$=CHR$(27)+"[81;68p"

Run the program, enter DOS, and TYPE the program. Uppercase Q should again produce a 0.

40 Function Keys

Now let's create some extra function keys. By supplying an extended ASCII code, you can redefine the ten function keys alone or in conjunction with the Ctr1, Shift, or Alt keys. That comes to four sets of ten, or 40 keys. Rerun the example program after changing line 10 as shown here:

AS 10 A$=CHR$(27)+"[0;84;"+CHR$(
      34)+"DIR"+CHR$(34)+"; i3p"

The following text file is created:

ESC [0;84;"DIR";p

The 0 before the 84 tells the computer to look for an extended keycode--a code that signals a special key combination. The extended keycode 84 represents Shift-Fl. What we've done is redefine this key combination so that it prints DIR followed by a carriage return. Run the program, exit to DOS, and type KEY.TXT again. Hold down Shift and press Fl: the disk directory is displayed.

Note the number 13 just before the p in this character sequence. This is the ASCII code for Return. Adding this character to the end of a character sequence has the same effect as pressing RETURN manually on the keyboard. The computer types the letters D-I-R, then issues a Return to carry out the command. You can find a complete list of all the extended keycodes on page G-7 of the IBM BASIC manual.

Screen Modes And Colors

Using a similar method, you can also change the screen color or shift to a different screen resolution. To change colors, replace the lowercase pin line 10 with a lowercase m, and supply an appropriate color number. For instance, change line 10 as shown here and create a new KEY.TXT file:

EN 10 A$=CHR$(27)+"[37;44m"

Now the program creates this text file:

ESC [37;44m

When this file is TYPEd from DOS the screen turns blue.

The same procedure works for changing the screen mode. Change line 10 to this (note that an h is substituted for the m in the preceding example):

BG 10 A$=CHR$(27)+"[=1h"

When you TYPE the resulting file from DOS, the screen goes into 40 X 25 color text mode. To obtain 320 x 200 color graphics mode, simply change the number 1 in line 10 to a 4. Pages 13-9 and 13-10 in the DOS 2.0 manual contain a complete listing of all the numbers for different screen modes and color combinations,

The customizations you create using these techniques will stay in effect as long as you are working in DOS or a DOS-related program such as DEBUG or EDLIN. If you're tired of the normal white-on-black screen display, this simple technique can bring a welcome change. Note, however, that these changes disappear if you reboot the computer, go to BASIC, or run an application that imposes its own definitions on the system.