home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / TNH_PC.ZIP / HOSKINS.NL < prev    next >
Encoding:
Text File  |  1987-01-14  |  8.5 KB  |  296 lines

  1. Getting to Know DOS 2.0: The
  2. Extended Keyboard Control Device
  3. Driver
  4.  
  5.           Josiah C. Hoskins
  6.    Central Texas IBM PC Users Group
  7.  
  8. One of the advanced features offered
  9. by DOS 2.0 is the extended keyboard
  10. control device driver (KCDD).  This
  11. feature allows the user to reassign
  12. the meaning of any key on the
  13. keyboard.  An example program
  14. (PCKEY.BAS) which permits the user
  15. to assign character strings to 20
  16. different function keys (the 10 base
  17. keys and the 10 shift function keys)
  18. is shown below. This program exists
  19. in a separate file as PCKEY.BAS and
  20. may be copied to your work disk.
  21. This program can be used as is by
  22. the novice, or as a model for
  23. setting up key reassignment programs
  24. for advanced programmers. A
  25. discussion is also included to aid
  26. in initializing the KCDD; a step
  27. which is necessary before using
  28. PCKEY.
  29.  
  30. First, let's ask ourselves, what is
  31. a device driver?  The DOS manual
  32. states that a device driver is a
  33. file which identifies a device
  34. (i.e., keyboard, printer, virtual or
  35. RAM disk, etc.), defines the
  36. strategy and interrupt entry points,
  37. and defines various attributes of
  38. the device.  For our purposes we
  39. shall use a device driver that is
  40. provided with the DOS 2.0 diskette,
  41. ANSI.SYS, which contains the
  42. character device driver.  This file
  43. follows the American National
  44. Standards Institute (ANSI) for the
  45. sequences of special character
  46. strings for terminal control
  47. functions (i.e., cursor positioning,
  48. clearing the display, etc.).  It is
  49. one of these functions defined by
  50. ANSI that allows keyboard key
  51. reassignment.
  52.  
  53. Now, let's briefly examine the code
  54. of PCKEY.BAS.  Lines 20 through 100
  55. turn off the key prompts, clear the
  56. screen, and print a logo for the
  57. program.  Lines 110 through 130
  58. undefine the ten function keys
  59. normally used by IBM BASIC.  Lines
  60. 140 through 290 set up the string
  61. assignment for key redefinition.
  62. Lines 300 to 410 create the file
  63. KEYON which is used to activate the
  64. key definitions you have chosen.
  65. Lines 420 to 450 create the file
  66. KEYOFF which turns off the key
  67. definitions.  Lines 460 through 510
  68. set up a help file called KEYHELP
  69. which contains the key definitions
  70. you have chosen.  Lines 520 to 540
  71. redefine the normal IBM BASIC
  72. function keys.
  73.  
  74. We are now ready to set up the files
  75. needed to perform our key
  76. reassignments under DOS 2.0.  First,
  77. we must configure our system.  To do
  78. this we create a file called
  79. CONFIG.SYS (note: this file must be
  80. in the root directory) in the
  81. following manner, enter
  82.  
  83.       A>COPY CON: CONFIG.SYS
  84.         DEVICE=ANSI.SYS
  85.  
  86. now press F6 then press Enter.  DOS
  87. will respond with the message "1
  88. File(s) copied".  Next, copy the DOS
  89. file ANSI.SYS to the root directory
  90. if it is not already there. Run the
  91. PCKEY program in BASIC.  When the
  92. prompt "Press key to be defined or
  93. <end> to stop" appears, either press
  94. any of the base function keys or
  95. shift function keys or the End key
  96. (i.e., the 1 key in the edit mode).
  97. If you press an allowed function key
  98. (for example, F1), the following
  99. prompt "Enter string to be assigned
  100. to F1 ?" will appear.  You may enter
  101. any string up to 68 characters long.
  102. If you include <CR> at the end of
  103. your chosen string, a carriage
  104. return will occur automatically
  105. after the chosen string is typed.
  106. After defining the desired function
  107. keys, press the End key.  The files
  108. KEYON, KEYOFF, and KEYHELP will be
  109. created (if they are not created in
  110. the root directory you should put
  111. them there).  Now return to DOS by
  112. entering SYSTEM.  To activate the
  113. new key definitions, enter TYPE
  114. KEYON.  To see the key definitions
  115. at any time, enter TYPE KEYHELP.  To
  116. turn off the key definitions, enter
  117. TYPE KEYOFF (you should turn off
  118. your key definitions when you use
  119. any software that defines any of the
  120. keys that you defined).
  121.  
  122.      PC-KEY HELPER
  123. Present Key Definitions are:
  124.  
  125.       F 1=type keyhelp<cr>
  126.       F 2=cls<cr>
  127.       F 3=type
  128.       F 4=copy
  129.       F 5=
  130.       F 6=
  131.       F 7=
  132.       F 8=
  133.       F 9=
  134.       F10=type keyoff<cr>
  135.     s-F 1=dir
  136.     s-F 2=
  137.     s-F 3=
  138.     s-F 4=
  139.     s-F 5=
  140.     s-F 6=
  141.     s-F 7=
  142.     s-F 8=
  143.     s-F 9=
  144.     s-F10=chkdsk<cr>
  145.  
  146. 10 REM ***** PC - KEY *****
  147. 20 KEY OFF : CLS
  148. 30 LOCATE 5,21 : PRINT CHR$(201)+
  149.    STRING$(38,205)+CHR$(187) :
  150.    LOCATE 6,21 : PRINT CHR$(186)
  151.    +STRING$(38," ")+CHR$(186)
  152. 40 LOCATE 7,21 : PRINT CHR$(186)+
  153.    STRING$(15," ")+"PC - KEY"+
  154.    STRING$(15," ")+CHR$(186) :
  155.    LOCATE8,21
  156. 50 PRINT CHR$(186)+STRING$(38," ")
  157.    +CHR$(186) : LOCATE 9,21 :
  158.    PRINT CHR$(186)+" Key
  159.    Definition Program For DOS
  160.    2.0 "+CHR$(186)
  161. 60 LOCATE 10,21 : PRINT CHR$(186)+
  162.    STRING$(38," ")+CHR$(186) :
  163.    LOCATE 11,21
  164. 70 PRINT CHR$(186)+"
  165.    Version 1.00            "+
  166.    CHR$(186) : LOCATE 12,21 : PRINT
  167.    CHR$(186)+STRING$(38," ")+
  168.    CHR$(186)
  169. 80 LOCATE 13,21: PRINT CHR$(200)+
  170.    STRING$(38,205)+CHR$(188) :
  171.    LOCATE 17,36 : PRINT "Written
  172.    By"
  173. 90 LOCATE 19,30: PRINT "Josiah
  174.    Collier Hoskins" : LOCATE 23,26
  175.    : PRINT "Press space bar to
  176.    continue..."
  177. 100 A$=INKEY$ : IF A$="" THEN 100
  178. 110 CLS : DIM K$(20),KN$(20)
  179. 120 FOR I=1 TO 10 : KEY I,"" :
  180.     NEXT I  'kill softkeys defined
  181.     in Basic
  182. 130 FOR I=1 TO 20 : K$(I)="" :
  183.     NEXT I
  184. 140 PRINT "Key definitions:"
  185. 150 FOR I=1 TO 20 : IF I>10
  186.     THEN 170
  187. 160 LOCATE 2+I,10 : PRINT "F"+
  188.     STRING$(68," "); : LOCATE 2+I,
  189.     11 : PRINT RIGHT$(STR$(I),2)+
  190.     "="; : GOTO 180
  191. 170 LOCATE 2+I,8 : PRINT "s-F"+
  192.     STRING$(68," "); : LOCATE 2+I,
  193.     11 : PRINT RIGHT$(STR(I-10),2)
  194.     +"=";
  195. 180 PRINT K$(I) : NEXT I
  196. 190 LOCATE 23,1 : PRINT STRING$
  197.     (79," ") : LOCATE 23,1 : PRINT
  198.     "Press to key to be defined
  199.     or<End> to stop"
  200. 200 R$=INKEY$ : IF R$ ="" THEN 200
  201.     ELSE IF LEN(R$)<>2 THEN 200
  202. 210 IF ASC(LEFT$(R$,1))<>0 THEN 200
  203.     ELSE R=ASC(RIGHT$(R$,1))
  204. 220 IF R >= 59 AND R <= 68 THEN 250
  205.     'base function keys
  206. 230 IF R> = 84 AND R <= 93 THEN 270
  207.     'shift function keys
  208. 240 IF R = 79 THEN 300 ELSE GOTO
  209.     190                'end key
  210. 250 R = R - 58 : LOCATE 23,1 :
  211.     PRINT STRING$(79," ") : LOCATE
  212.     23,1
  213. 260 PRINT "Enter string to be
  214.     assigned to F";R; : GOTO 290
  215. 270 R = R-83 : LOCATE 23,1 : PRINT
  216.     STRING$(79," ") : LOCATE 23,1
  217. 280 PRINT "Enter string to be
  218.     assigned to s-F";R; : R = R +
  219.     10
  220. 290 R$="" : INPUT R$ : K$(R)=R$ :
  221.     GOTO 150
  222. 300 KEYDEF$ = "KEYON" :
  223.     OPEN KEYDEF$ FOR OUTPUT AS #1
  224.     'create file to turn on keys
  225. 310 CR$ = "<CR>" : CR2$ = "<cr>" :
  226.     FOR I=1 TO 20 : IF K$(I)=""
  227.     THEN 390
  228. 320 IF CR$ = RIGHT$(K$(I),4) OR
  229.     CR2$ = RIGHT$(K$(I),4) THEN
  230.     360
  231. 330 IF I > 10 THEN 350
  232. 340 PRINT #1,CHR$(27)+"[0;"+RIGHT$
  233.     (STR$(I+58),2)+";"+CHR$(34)+K$
  234.     (I)+CHR$(34)+";"+32p" : GOTO
  235.     410
  236. 350 PRINT #1,CHR$(27)+"[0;"+RIGHT$
  237.     (STR$(I-10+83),2)+";"+CHR$(34)+
  238.     K$(I)+CHR$(34)+";"+"32p" : GOTO
  239.     410
  240. 360 NOL = LEN(K$(I)) :N = NOL - 4 :
  241.     KN$(I) = LEFT$(K$(I),N) : IF I
  242.     > 10 THEN 380
  243. 370 PRINT #1,CHR$(27)+"[0;"+RIGHT$
  244.     (STR$(I+58),2)+";"+CHR$(34)+
  245.     KN$(I)+CHR$(34)+";+"13p" : GOTO
  246.     410
  247. 380 PRINT #1,CHR$(27)+"[0;"+RIGHT$
  248.     (STR$(I-10+83),2)+";"+CHR$(34)+
  249.     KN$(I)+CHR$(34)+";"+13p" : GOTO
  250.     410
  251. 390 IF I>10 THEN 400 : PRINT #1,
  252.     CHR$(27)+"[0;"+RIGHT$(STR$
  253.     (I+58),2)+";0;"+RIGHT$(STR$
  254.     (I+58),2)+"p" "GOTO 410
  255. 400 PRINT #1,CHR$(27)+"[0;"+RIGHT$
  256.     (STR$(I-10+83),2)+";0;"+RIGHT$
  257.     (STR$(I-10+83),2)+"p"
  258. 410 NEXT I : CLOSE #1
  259. 420 KEYNOT$ = "KEYOFF" : OPEN
  260.     KEYNOT$ FOR OUTPUT AS #2 :
  261.     FOR I=1 TO 20 : IF I>10 THEN
  262.     440  'create file to turn off
  263.     keys
  264. 430 PRINT #2,CHR$(27)+"[0;"+RIGHT$
  265.     (STR$(I+58),2)+";0;"+RIGHT$
  266.     (STR$(I+58),2)+"p" :GOTO 450
  267. 440 PRINT #2,CHR$(27)+"[0;"+RIGHT$
  268.     (STR$(I-10+83),2)+";0;"+"RIGHT$
  269.     (STR$(I-10+83),2)+"p"
  270. 450 NEXT I : CLOSE #2
  271. 460 HELPER$ = "KEYHELP" : OPEN
  272.     HELPER$ FOR OUTPUT AS #3
  273.     'create help file
  274. 470 PRINT #3, "PC - KEY  HELPER =>
  275.     Present Key Definitions are:"
  276. 480 FOR I=1 TO 20 : IF I>10 THEN
  277.     500
  278. 490 PRINT #3,"          F"+RIGHT$
  279.     (STR$(I),2)+K$(I) : GOTO 510
  280. 500 PRINT #3,"        s-F"+RIGHT$
  281.     (STR$(I-10),2)+"="+K$(I)
  282. 510 NEXT I : CLOSE #3
  283. 520 KEY 1,"LIST"+CHR$(32) : KEY 2,
  284.     "RUN"+CHR$(13) : KEY 3,"LOAD"+
  285.      CHR$(34) : KEY 4,"SAVE"+
  286.      CHR$(34) : KEY 5,"CONT"+
  287.      CHR$(13)
  288. 530 KEY 6,","+CHR$(32)+"LPT1"+
  289.     CHR$(13) : KEY 7,"TRON"+
  290.     CHR$(13) : KEY 8,"TROFF"+
  291.     CHR$(13) : KEY 9,"KEY"+CHR$(32)
  292. 540 KEY 10,"SCREEN 0,0,0"+CHR$(13)
  293.     'normal basic softkeys turned
  294.     back on
  295. 550 END
  296.