MACROS.DOC  ·  DOC  ·  17.8 KB  ·  1987-01-21  ·  from CompuLink-User-Group_Magazette_Feb-1987
                 New macros to pep up older MS Dos software
                       (Examples using Perfect Writer)
                                 Mike Guffey

    The undocumented trick of using the MSDOS "prompt" command to redefine
    some keyboard combinations is becoming more widely  known  this  year.
    It  is  a  nifty  (and  free) alternative to commerical software which
    performs similar (but  often  more  sophisticated)  functions.   Using
    "prompt"  can  add  new life to older MSDOS software.  But it has some
    limitations which restrict its usefulness for some.  And many  others,
    upon learning the redefinition trick, have a reaction which boils down
    to, "Oh, wow!  -- So?"

    The first limitation of using "prompt" to redefine keys is that  there
    is  a  limit to the number of keys which can be defined this way.  The
    portion of memory set aside by MSDOS for such nifty things  is  called
    ENVIRONMENT  SPACE.   This  spot  in  memory  is not very large.  That
    leaves you with a choice of several short definitions or a few  longer
    (but  not  too  long)  ones.  If the limit is exceeded, some keys just
    don't get redefined.  Worse yet, other things (parameters such as path
    and  comspec)  which  are supposed to reside in that small spot may be
    interfered with or  be  left  without  a  home.   There  is  not  much
    understandable  information available to non-technoid users about this
    mysterious spot in memory.  As a result, some may choose to bypass the
    convenience that the "prompt" command can provide.

    The  second  problem  is  that programming more sophisticated keyboard
    strings (hereafter called "macros") requires a  bit  more  imagination
    than  some  are  willing  to  devote  to  an  undocumented  feature of
    MicroSoft DOS.  The "prompt" command can often be used  to  program  a
    sequence of commands into one key-combination.  It can also be used to
    make commands mnemonic (easier to remember) by  assigning  keys  which
    make  more  sense than those chosen by the software developers.  Or it
    can be used to redefine keys  (especially  Function  keys)  which  you
    don't  chose  to  use  after  you  are familiar with the software.  An
    example is redefining the <F1> key for  something  besides  calling  a
    HELP file you have outgrown.

    A FEW WORDS ABOUT ENVIRONMENT SPACE

    This  is  a  spot  in  memory  located  between  the command processor
    (COMMAND.COM)  and  the  first  application  program  (including  your
    AUTOEXEC file).  It only holds 160 characters and some of that is used
    up as overhead delineating the start and stop of some things which you
    define  with commands such as "path".  (You can see the parameters you
    have specified by entering the SET command at the DOS command prompt.)
    The  Environment  Space  can  be  manually  increased before the first
    program is loaded or  by  a  Public  Domain  program.   It  cannot  be
    increased  in size by other means.  Even your AUTOEXEC file will cause
    the environment size to be frozen.

    One solution is to use the SET command to manually  define  (from  the
    command  line)  several  dummy  parameters.   You  will  then  need to
    (manually) use the SET command again to undefine them.  Then  you  can
    manually  start  a .BAT file to continue your start-up sequence.  This
    is not so much a solution as torture.   It  would  make  the  "prompt"
    method  of  redefining  many  keys  a  tedious process of questionable
    value.

    Of course, you can choose to use only a  limited  number  of  "prompt"
    redefinitions.   This  works well for most.  But if you have a need to
    redefine many keys, your options are to face this dilemma or invest in
    commercial  software.   There IS an alternative (to manually enlarging
    the Environment Space).  It is a shareware  program  residing  in  the
    Public Domain called ENVSIZE.  The function of this program is to make
    your Environment Space larger and to allow your  start-up  process  to
    remain  automated.   The  program  is  generally available on BBS's as
    ENVSIZE.ARC.  It is of use if you want to redefine a lot of keys using
    the  "prompt"  command.  The documentation which accompanies it does a
    good job of explaining how it works and how to use it.  (If you cannot
    find  ENVSIZE,  contact  its  author,  Charles P.  Scott at 519 Garden
    Springs Drive;  Mt.  Sterling, KY, 40353).

    GETTING THE MOST OUT OF KEY REDEFINITIONS WITH "PROMPT"

    A review of the "prompt" command sequence:

    - in order to redefine keys  with  "prompt",  you  need  to  have  the
    ANSI.SYS file in your root directory and the line "DEVICE=ANSI.SYS" in
    your CONFIG.SYS file;  the redefining will NOT work unless  these  two
    requirements are fulfilled

    -  while  the  issue  of ENVIRONMENT SPACE is worth noting, the use of
    "prompt"  to  redefine  keys  will  still  work  if  you  accept  that
    redefinitions  will  be  limited;   the  number  of  keys which can be
    redefined is related to how long each definition (or "macro") is

    - keyboard redefinition with "prompt" will not work with some types of
    software  which  bypass MSDOS for any number of reasons;  two examples
    are BASIC and SMART software

    - after keys have been redefined (usually in an .BAT file)  they  will
    retain  new  definitions  until  the  system is re-booted (or they are
    redefined);  the keys can also be  redefined  as  a  series  of  <ESC>
    sequences  in an ASCII file (but this will not enlarge the space where
    definitions are stored)

    - the last command (when using "prompt") of a redefinition series must
    be  a  prompt  command to redefine the command line prompt;  otherwise
    there will be no prompt and the com{xwd line will  begin  at  the  far
    left margin ("prompt" with no arguments can suffice)

    -  a  "prompt" key redefinition is made up of several parts, separated
    by semicolons:

           prompt $e[0;nn;"xxxxxxxxxxx";nnp
           ^^^^^^^^^^^
           |          ^^^
           |           |  ^^^^^^^^^^^^^^
           |           |      |        ^^^^
           |           |      |         |____optional ending character
           |           |      |______________ASCII key redefinition string
           |           |_____________________numeric key value (see table)
           |_________________________________fixed beginning sequence

    - the beginning sequence is always the same (for key definitions)

    - the numeric key value (table  below  lists  the  choices)  specifies
    which key is to be redefined <nn = key>

    - the ASCII string may include <CTRL> characters;  quotation marks are
    mandatory at both ends of a string (or "macro")

    - the optional ending character can be used to enter ASCII  characters
    to  end the newly defined string which cause a problem with the prompt
    command itself or with software used to create the command(s);  the nn
    value  is  decimal  and  the ending "p" is required;  two examples are
    <RETURN> (decimal value of 13) and <ESC> (decimal value of 27)

    SO MUCH FOR THE SMALL TALK, HERE ARE SOME EXAMPLES

    All of us have a taste for things comfortable and familiar.   Thus  it
    is  with  software.  In spite of nifty, affordable, and (often) better
    new products, many of us keep plugging away on our  old  and  evermore
    kludgy favorites.

    Perfect  Writer  is one such example.  It was first developed as a 64k
    RAM CP/M product.  Those fortunate enough to cut their computing teeth
    on  the  Kaypro  product  line  either  loved it or hated it.  Perfect
    Writer fans who migrate to MSDOS often find it possible to obtain  the
    PC  compatible  version  of  the  software.   For  those  who make the
    transition, the added features of Function keys  are  not  so  much  a
    convenience  as  an  annoyance.   Whoever  decided which Function keys
    would do what was not very imaginative.  This is why Perfect Writer is
    used as an example here.  What can be done to improve this program can
    become a proforma  example  of  things  to  do  with  other  cherished
    software favorites.

    The  MSDOS  version  of Perfect Writer defines all four flavors of the
    Function key set (Normal, Ctrl, Shift, Alt).  One of the least  useful
    (for a seasoned user) is the <F1> key.  It is used in Perfect software
    (and many other programs) to call up a help file.   It  is  a  natural
    candidate  for  redefinition.   The  <F4>  key,  which provides window
    commands, is a less-than-imaginative use of  key-combinations.   While
    easy  to remember, the key-combinations are awkward to press.  Why not
    re-define other keys mnemonically and recover  the  four  versions  of
    this key for something else?  There is also the infamous reserved <F9>
    key.  It never was defined and is useless  without  key  redefinition.
    Four easy-to- press combinations seem to cry out to be of some use.

    Sometimes  there  are  reasons  to redefine perfectly useful keys when
    software is used by inexperienced users.   I  have  developed  Perfect
    Writer  for  my employer as a free-form database for warranty records.
    For this  reason,  I  disable  certain  keys  (using  "prompt")  while
    training  new  operators.  Because of the size of some of the database
    files, I had to redefine the <F7> key from "Find File" to "Read File".
    This  prevents filling up buffers and encountering the dreaded "Out of
    Memory!" or "Swap File Full"  messages.   Both  error  conditions  can
    scramble a file if the File Write command is given just before or just
    after the condition occurs.  (These error conditions cannot be totally
    avoided  by  using  a RAMdisk or large swap files, but that is another
    story.)

    Another use for the "prompt" redefinition scheme is that some keys can
    be  customized for the needs or preferences of specific operators.  As
    operator proficiency increases, the keys can be returned  to  original
    values  as  the  need  to  "idiot proof" the software diminishes.  The
    redefinitions are especially useful in programming a key  or  keys  to
    enter   a   form  design  for  data  entry.   A  sequence  of  several
    hard-to-remember commands can be reduced to a single  key-combination.
    [By  the way, Perfect Writer allows the correct use of cursor movement
    keys when the number pad is in the <NUMLOCK> condition.  This is  done
    by pressing <SHIFT> at the same time as the cursor movement key.  This
    feature is not unique to this software;  many MSDOS programs allow it.
    It certainly speeds data entry.]

    One  of  the  more  annoying  limitations of the "prompt" redefinition
    method is that some <CTRL> characters will not work in the middle of a
    string  definition.   Strings  requiring  a  <RETURN>/<CTRL-M>  in the
    middle will need to be defined as two keys.  The first key is  defined
    through  the  <RETURN>  but  the  actual <RETURN> character is defined
    outside  the  ASCII  string  enclosed  in  quotes.
    EXAMPLE:
                        prompt $e[0;33;"^XIfmt.";13p

                    Defines <ALT-F> to insert FMT.  file
                and adds <RETURN> to the end of the command.
               (Functionally equal to <Ctrl-X>, I, fmt., <CR>)

    Problems with most other characters of the ASCII code can be  resolved
    by  a  little-used  feature  of  Perfect  Writer.  (Other software may
    afford a similar solution.) Sometimes it  is  useful  to  be  able  to
    insert  control characters in a file.  An example is inserting printer
    control codes instead of running the file through a separate,  usually
    tedious,  formatting routine.  In Perfect Writer, use of <CTRL-Q> will
    allow the next character to be anything below (or  above)  the  normal
    alphanumeric  character set.  To enter the true value of <CTRL-A>, for
    example, press <CTRL-Q> then <CTRL-A>.   (To  get  Perfect  Writer  to
    accept  values  above  128 decimal, hold down the <ALT> key, enter the
    decimal value, then release the <ALT> key.  Of  course,  you  need  to
    enter <CTRL-Q> first.)

    [Other  control  characters  which "prompt" (and your WP software) may
    have trouble with are:  <CTRL-J>/LineFeed, <CTRL-I>/Tab.]

    Getting Perfect Writer to accept the control characters in the  proper
    fashion  can  be  tricky.   If you redefine a key to insert <ESC>E (to
    turn on boldface/emphasized print on an Epson compatible printer)  you
    won't get the proper result.  You have the include the <CTRL-Q> in the
    definition.  Thus, a "prompt" macro to  insert  commands  to  make  an
    entire line boldface is:

                               ^Q^[E^Q^E^Q^[F

                            instead of:  ^[E^E^[F

    The   second   macro   would   cause   END-OF  SENTENCE,  END-OF-LINE,
    JUMP-TO-NEXT-WORD to be recognized instead of  printer  control-  code
    sequence.   The use of printer control codes will be erased if you run
    the file through Perfect Formatter.  This trick  is  for  enhancing  a
    finished  ASCII  file.   (The  .FIN files are not ASCII.  To create an
    ASCII file with PF.COM, insert the command @DEVICE(file) as the  first
    line  before  formatting.) If you prefer to use Perfect Formatter, the
    same results can be acheived with the macro, "@B[^Q^E]".

    Using the true printer control code sequences allows  Perfect  Printer
    to be bypassed.  Instead, you give the command to COPY the filename to
    PRN on the DOS command line.  It also allows some  types  of  printing
    which  Perfect  Formatter  cannot  set.  My off-brand printer will not
    accept the Perfect Formatter command for italics.  Instead, it  prints
    out  double-strike  underlined.   By  inserting the true control codes
    into an ASCII file, I can finally  mix  regular  and  italics  without
    running through some other word processing program.

    One final note on inserting printer control codes via "prompt" macros.
    Some   printers   require   the   equivalent   of   <ESC><CTRL-@>   to
    reset/initialize  the  printer.   The numeric value of <CTRL-@> is 00.
    Most software will not allow you to enter this value.  The way  I  get
    around it is to set up a .BAT file with my "prompt" commands and use a
    dummy value (usually "Z")  where  I  need  <CTRL-@>.   Then  I  use  a
    HEX/ASCII  (or  byte-level)  editor to change the value of that single
    character.  This is also a way to insert  control  characters  into  a
    "prompt" macro if your word processing software doesn't have something
    like Perfect Writer's <CTRL-Q>.  [The <CTRL-@> can also  be  generated
    by    ending   the   "prompt"   string   with   ;00p   (i.e.    prompt
    $e[0;33;"^Q^[";00p).]

    CLOSING NOTES AND SAMPLE PERFECT WRITER MACROS

    Well, that's about it.  The purpose of this article was to  expand  on
    my  earlier piece, PROMPT.INF (also, PROMPT.ARC).  It is to give you a
    nudge towards using this really nifty MSDOS trick.  You will  probably
    find,  as I have, that you don't really need to redefine too many keys
    to give old software new zip and  added  convenience.   What-the-heck,
    "prompt"  key  redefinition  costs  nothing more than a little of your
    time.  Less expensive software is not available.

    A few of my favorite Perfect Writer macros:
 
    prompt $e[0;33;"^XIFMT";13p      <ALT-F> to insert FMT.MSS file
    prompt $e[0;46;"@CENTER{         <ALT-C> to insert center command
    prompt $e[0;47;"@VERBATIM{";13p  <ALT-V> to insert verbatim<CR>
    prompt $e[0;49;"@NEWPAGE";13p    <ALT-N> to insert newpage <CR>
    prompt $e[0;59;"^A"              <F1> as move cursor to line start
    prompt $e[0;60;"^E"              <F2> as move cursor to line end
    prompt $e[0;62;"^Q^[E^Q^[F^Q^[F" <F4> to make a single word
                                 boldface (for ASCII/non-FIN files only)
    prompt $e[0;65;"^Xd"             <F7> to give disk directory
    prompt $e[0;67;"^D"              <F9> as delete one character
    prompt $e[0;82;"^Y"              <INS> as Yankback
    prompt $e[0;120;"^X1"            <ALT-1> as return to single window
    prompt $e[0;121;"^X2"            <ALT-2> as split window at cursor
    prompt $e[0;24;"^XO"             <ALT-O> as go to other window
    prompt $e[0;34;"^X^"             <ALT-G> to "grow" current window
    prompt [optional arguments]      must be the last command


    Key values used for redefining keys with "prompt"

         F1 = 59 F2 = 60 F3 = 61 F4 = 62 F5  = 63
         F6 = 64 F7 = 65 F8 = 66 F9 = 67 F10 = 67

         Shift-F1 = 84 Shift-F2 = 85 Shift-F3 = 86 Shift-F4 = 87
         Shift-F5 = 88 Shift-F6 = 89 Shift-F7 = 90 Shift-F8 = 91
         Shift-F9 = 92 Shift-F10 = 93

         Ctrl-F1 = 94 Ctrl-F2 = 95 Ctrl-F3 = 96 Ctrl-F4 = 97
         Ctrl-F5 = 98 Ctrl-F6 = 99 Ctrl-F7 = 100 Ctrl-F8 = 101
         Ctrl-F9 = 102 Ctrl-F10 = 103

         Alt-F1 = 104 Alt-F2 = 105 Alt-F3 = 106 Alt-F4 = 107
         Alt-F5 = 108 Alt-F6 = 109 Alt-F7 = 110 Alt-F8 = 111
         Alt-F9 = 112 Alt-F10 =113

         Alt-1 = 120 Alt-2 = 121 Alt-3 = 122 Alt-4 = 123
         Alt-5 = 124 Alt-6 = 125 Alt-7 = 126 Alt-8 = 127
         Alt-9 = 128 Alt-0 = 129 Alt-- = 130 Adt-= = 131

         Alt-A = 30 Alt-B = 48 Alt-C = 46 Alt-D = 32 Alt-E = 18
         Alt-F = 33 Alt-G = 34 Alt-H = 35 Alt-I = 23 Alt-J = 36
         Alt-K = 37 Alt-L = 38 Alt-M = 50 Alt-N = 49 Alt-O = 24
         Alt-P = 25 Alt-Q = 16 Alt-R = 19 Alt-S = 31 Alt-T = 20
         Alt-U = 22 Alt-V = 47 Alt-W = 17 Alt-X = 45 Alt-Y = 21
         Alt-Z = 44