DK
Define Keys For The MS-DOS

DK is freeware by Michael Walter

What is DK ?
Which keys can be defined ?
What can be assigned to a key ?
Using DK together with command line editors
Output and messages
Help
Defining keys at system startup
How do I know what keys are defined?
Example Key Definition File
[List of Downloads]

What is DK ?

DK lets you define keys and key combinations for the DOS command line. DK works on the IBM PC and compatible computers. Key definition is achieved by means of ANSI escape sequences. Hence DK requires ANSI.SYS to be loaded. The file can be loaded by including the line DEVICE=ANSI.SYS in your CONFIG.SYS file. If the ANSI.SYS driver is not located in the root directory on your system you must specify the path. There are freeware and shareware replacements for ANSI.SYS which may even be preferable to it.

DK lets you assign one or more DOS commands or strings to a single key or a key combination.

[Table of Contents]

Which keys can be defined ?

You can define the following keys:

Almost all of these keys can be defined in combination with the ALT, CTRL and SHIFT keys.

NOTE

In a number of cases you will define more than one key or key combination with a single key definition. For example, if you define CTRL/M the ENTER key is also defined.

It is not advisable to define some key combinations. Defining CTRL/M, for example, means that you will not be able to enter DOS commands after that because you have lost the [RETURN] key. Likewise, if you define the CTRL/S key combination you will no longer be able to stop and restart output to the screen.

[Table of Contents]

What can be assigned to a key ?

Basically, you can assign any string to a key. On pressing the key, the string you have assigned to it is inserted in the command line at the current cursor position. To avoid overwriting of data you have already entered, press the Ins key first.

Strings you might want to assign to a key might be DOS commands including the names of batch files, lengthy options required by a program, long pathnames you use often or what else you can think of.

DOS commands can be also be executed on pressing the defined key. Because DK only defines keys but does not execute anything it is necessary to append and end-of-line character to the command. This corresponds to pressing the [RETURN] key.

The following key definition shows you how to do that:

C:\> DK F1 DIR^n

DK recognizes a number of escaped characters such as ^n which is taken to mean the end-of-line character.

Strings may be enclosed in double quotation marks but this should rarely be necessary. Generally, you should first try without the spaces if you have an awkward string that you think might cause problem (such a string would be "dir a:\", for example). You will need quotation marks when assigning strings that start with a "-" or a "/" because otherwise DK would try to make sense of the strings as options for its own processing.

[Table of Contents]

Using DK together with command line editors

If you use CED (Command line EDitor) or any other history utility that allows you to define abbreviations for commands you can also use such abbreviated commands.

CED uses a special character that serves as a delimiter between DOS commands. This may also be true for other similar utilities. If this character happens to be the '^' character, which is the escape character used by DK, you have three choices:

  1. Enclose the assignment string in double quotation marks

  2. Use the facilities provided by the history utility to define a different escape character for its use.

    The appropriate CED command would be:

    C:\> CED CHAINCH character

    for example:

    C:\> CED CHAINCH @

    to define the '@' character as the escape character to be used by CED.

  3. Use the /E option to DK to enforce its use of a different escape character.

    By default, you would use the following command to assign to the F1 key the task of clearing the screen and displaying a directory listing:

    C:\> DK F1 "cls^n dir^n"

    To enforce the use of '&' instead of '^' you need to change the command to:

    C:\> DK F1 "cls&n dir&n" /E&

    DK will override DOS's use of function keys. If, for example, the key F3 is defined using DK, the normal F3 function (recall the last DOS command) will be overruled by the new key assignment.

    [Table of Contents]

    Output and messages

    Messages that DK sends to standard output (normally the screen) can be suppressed by piping them to the null device like in the following command:

    C:\> DK ALT/F1 "dir|more" > NUL

    You can also negate the /l switch by appending a minus sign to it to achieve the same result.

    C:\> DK ALT/F1 "dir|more" /l-

    Error messages are sent to standard error (the screen) and can not be suppressed.

    [Table of Contents]

    Help

    A brief reminder of the command syntax and other information is displayed if you use the DK command without any arguments.

    [Table of Contents]

    Defining keys at system startup

    There will probably be some often used commands that you would like to be tied to a key every time you start a session. To achieve this create a file containing key names and their definitions and have DK execute this file at system startup by inserting a command like the following in your AUTOEXEC.BAT file:

    DK /Fmykeys.def

    How do I know what keys are defined?

    DK is not a TSR program. This is why it cannot keep the definitions it has created in memory. It has another way of keeping track of key definitions, however. Whenever you define a key DK writes the name of the key and its definitions to a log file called DKINFO.DAT.

    By default, this file is looked for in the root directory of your current drive. You can specify a different directory by defining an environment variable called DKDIR as in the following example:

    C:\> SET DKDIR=c:\dk

    Now, if you want to see your key definitions you can type the info file to the screen. The easiest way to do this is to assign this command to a key, of course:

    C:\> DK F6 type c:\dk\dkinfo.dat^n

    A definition that you could use in cases where you know a part or whole of the command but not which key it is assigned to, is the following:

    CTRL/F6 "type c:\dkinfo.dat|grep -i "

    On pressing CTRL/F6 the string shown above is entered on the command line and you can type the string that you are looking for and press [RETURN]. Grep is just a program that finds strings in files; replace it with the one that you use for that purpose.

    If you don't want a definition to be written to the info file you can specify the /I option in the DK command, followed by a minus sign:

    C:\> DK /i- F10 "string"

    The point in not having a definition written to the info file is that the info file is kept in a format that allows you to use the file as key definition input file again. This way, if you have a command like

    C:\> DK /fdkinfo.dat

    in your AUTOEXEC.BAT file, you can define a key during your DOS session and have it available after the next boot.

    [List of Downloads] [Table of Contents]

    Example Key Definition File

    The following examples are part of the kit that you should have received when you obtained DK. They are found in the file DKSAMPLE.DEF.

    The key definitions shown and explained below use many of the features of DK to help you get familiar with the utility.

    If there are differences between a definition from the DOS command line and from within a file both versions are given.

    DOS level: DK F1 "dir^n"
    File: F1 dir^n

    This definition lets you press the F1 key to display a Directory listing.

    The "^n" that terminates it stands for the pressing of the RETURN key. DK recognizes a number of special escape sequences. One of these characters is the "n" for newline. All these Escape characters must be preceeded by an escape sequence introducer which by default is the "^" character. The introducer can be changed with the /E switch.

    On the DOS command level the quotes are not normally necessary. There are, however, other command shells like for example 4DOS that might attach special meaning to the "^" character. The quotes around the whole definition keep such shells from interpreting any characters within quotes. When a key definition is placed in an input file, quotes are never needed because the command interpreter does not get a chance to interpret them.

    DOS level: DK ALT/F1 "dir|more^n"
    File: ALT/F1 dir|more^n

    The above example just adds the MORE filter to the DIRECTORY command. Otherwise there is nothing new about it.

    F3 xcopy /s *.* a:\

    This command is not automatically terminated as though you had Pressed the RETURN key. You get a chance to append something to it like for example the name of a directory on the diskette in drive A before you press RETURN yourself.

    DOS level: DK F4 "dirdel "
    File: F4 dirdel^x20

    This command inserts the string "dirdel " at the current cursor position. Dirdel is a utility that deletes a directory tree. The string "^x20" in the key definition from within a file tells DK to append a space character at the end of the string "dirdel". The space character is not represented by just inserting it in the normal way because DK removes blank space at the beginning and end of a definition. The character combination "^x20" means: insert the character whose hex value is 20. The "^" is the already known escape sequence introducer and the "x" introduces a hex number. The space character could also have been written in decimal notation as "^d032" or octal notation "^040".

    DOS level: DK F6 "type c:\dkinfo.dat|more^n"
    File: F6 type c:\dkinfo.dat|more^n

    The example above shows the easiest way to find out which definitions have keys have been assigned to which keys. It defines the F6 key to display the DK info file that is kept up-to-date by DK.

    DOS level: DK CTRL/F6 "type c:\dkinfo.dat|grep -i^x20"
    File: CTRL/F6 type c:\dkinfo.dat|grep -i^x20

    This key definition goes a step further by letting you search in the DK info file for a special definition. It assumes that you have a search utility installed (e.g. grep). Because grep needs the string to search for as its first parameter it can not be used directly (grep "string" c:\dkinfo.dat). Such a use would require you to move the cursor back in front of the file specification each time. The definition given above lets you append the search string to the command and press RETURN.

    ALT/F6 dk F10^x20

    The definition above lets you turn the current command into a Key definition with ease. You just press the HOME key to move to the beginning of the command line and press INS to get into insert mode (if this isn't you default mode anyway). Pressing the ALT/F6 key combination inserts the string "dk F10 " in front of the command and after pressing RETURN the command line is available by pressing F10.

    DOS level: DK F8 "time^n^n"
    File: F8 time^n^n

    This key definition shows how to handle commands that require user input. The DOS TIME command will display the current date and time and will prompt for a new time. Pressing RETURN brings you back to the DOS prompt. To save you that extra pressing of the RETURN key you can tell DK to do this for you by adding an additional "^n". The first executes the TIME command, the second terminates the prompting for a new time specification.

    ALT/D dk /fd:\dk\def\noreturn.def^n

    ! --- ALL commands (ALL is a utility that executes a command for all
    ! files in a list)
    ALT/A dir /b | all "? !fs!" /t

    ! --- Print commands
    CTRL/P print^x20


    [List of Downloads] [Table of Contents]

    DK is freeware by Michael Walter