home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / ascsu205.arj / GETKEY.ASI < prev    next >
Text File  |  1991-11-12  |  7KB  |  356 lines

  1. start:
  2.  
  3. rem GETKEY.COM
  4.  
  5. rem This command gets a key from the keyboard, Aa through Zz and 1 through 9,
  6. rem and returns an Errorlevel of 1 through 36. A or a returns 1, 9 returns 36.
  7. rem The function keys return 37-46, and Esc returns an Errorlevel of 0.
  8.  
  9. rem Alternatively, you can just display a message, with the /m parameter.
  10. rem Operation will suspend until any key is pressed.  With this parameter,
  11. rem GETKEY works just like DOS's PAUSE command, except that you can display
  12. rem the message of your choice, rather than be limited by "Strike a key" etc.
  13.  
  14. rem A third option is to get only a y or n response to a question, or the Esc 
  15. rem key (intended to be used for quitting the program, but you can probably 
  16. rem think of some other, more creative uses), with the /q (question) 
  17. rem parameter.  y or n can be either upper or lower case.
  18.  
  19.  
  20. rem First we get keyboard input, using command$, and place a space after it for 
  21. rem pretty printing.
  22.  
  23. a$=command$
  24. a$=a$+ " "
  25.  
  26. rem Now we check for the "message" parameter.
  27. d$=mid$(a$,1,3)
  28. if d$=" /m" then message:
  29. if d$=" /M" then message:
  30.  
  31. rem Here is the parameter for getting a y or n response.
  32. if d$=" /q" then getyn:
  33. if d$=" /Q" then getyn:
  34.  
  35. rem Here is the parameter for sending errorcodes to the system.
  36. if d$=" /e" then geterror:
  37. if d$=" /E" then geterror:
  38.  
  39. rem Here is the parameter for getting help.
  40. if d$=" /?" then help:
  41.  
  42. rem If no command line message, the user probably needs help.
  43. if a$=" "then checkhlp:
  44.  
  45. checkhlp:
  46. print "Do you need help? (y/n)";
  47.  
  48. wrongkey:
  49. wait4:
  50. wait$=inkey$
  51. if wait$="" then wait4:
  52. if wait$="y" then help:
  53. if wait$="Y" then help:
  54. if wait$="n" then sorry:
  55. if wait$="N" then sorry:
  56. goto wrongkey:
  57.  
  58. sorry:
  59. print wait$
  60. cls
  61. print "Sorry, this batch file command requires a command line message in order" 
  62. print "to do any meaningful work.  To get help, type GETKEY /?."
  63. goto finish:
  64. geterror:
  65.  
  66. rem If /e parameter, we print the message and wait for a key.
  67. d$=mid$(a$,5,79)
  68. print d$;
  69.  
  70. wait:
  71. b$=inkey$
  72. if b$="" then wait:
  73.  
  74. rem if function keys are pressed then goto the extended key reading module.
  75. if extended=1 then readext:
  76.  
  77. c$=chr$(27)
  78.  
  79. if b$=c$ then exit0:
  80.  
  81. if b$="a" then exit1:
  82. if b$="A" then exit1:
  83. if b$="b" then exit2:
  84. if b$="B" then exit2:
  85. if b$="c" then exit3:
  86. if b$="C" then exit3:
  87. if b$="d" then exit4:
  88. if b$="D" then exit4:
  89. if b$="e" then exit5:
  90. if b$="E" then exit5:
  91. if b$="f" then exit6:
  92. if b$="F" then exit6:
  93. if b$="g" then exit7:
  94. if b$="G" then exit7:
  95. if b$="h" then exit8:
  96. if b$="H" then exit8:
  97. if b$="i" then exit9:
  98. if b$="I" then exit9:
  99. if b$="j" then exit10:
  100. if b$="J" then exit10:
  101. if b$="k" then exit11:
  102. if b$="K" then exit11:
  103. if b$="l" then exit12:
  104. if b$="L" then exit12:
  105. if b$="m" then exit13:
  106. if b$="M" then exit13:
  107. if b$="n" then exit14:
  108. if b$="N" then exit14:
  109. if b$="o" then exit15:
  110. if b$="O" then exit15:
  111. if b$="p" then exit16:
  112. if b$="P" then exit16:
  113. if b$="q" then exit17:
  114. if b$="Q" then exit17:
  115. if b$="r" then exit18:
  116. if b$="R" then exit18:
  117. if b$="s" then exit19:
  118. if b$="S" then exit19:
  119. if b$="t" then exit20:
  120. if b$="T" then exit20:
  121. if b$="u" then exit21:
  122. if b$="U" then exit21:
  123. if b$="v" then exit22:
  124. if b$="V" then exit22:
  125. if b$="w" then exit23:
  126. if b$="W" then exit23:
  127. if b$="x" then exit24:
  128. if b$="X" then exit24:
  129. if b$="y" then exit25:
  130. if b$="Y" then exit25:
  131. if b$="z" then exit26:
  132. if b$="Z" then exit26:
  133. if b$="0" then exit27:
  134. if b$="1" then exit28:
  135. if b$="2" then exit29:
  136. if b$="3" then exit30:
  137. if b$="4" then exit31:
  138. if b$="5" then exit32:
  139. if b$="6" then exit33:
  140. if b$="7" then exit34:
  141. if b$="8" then exit35:
  142. if b$="9" then exit36:
  143. goto wait:
  144.  
  145. readext:
  146. print
  147. if b$=";" then exit37:
  148. if b$="<" then exit38:
  149. if b$="=" then exit39:
  150. if b$=">" then exit40:
  151. if b$="?" then exit41:
  152. if b$="@" then exit42:
  153. if b$="A" then exit43:
  154. if b$="B" then exit44:
  155. if b$="C" then exit45:
  156. if b$="D" then exit46:
  157. goto wait:
  158.  
  159. exit0:
  160. print
  161. end
  162. exit1:
  163. print b$
  164. end 1
  165. exit2:
  166. print b$
  167. end 2
  168. exit3:
  169. print b$
  170. end 3
  171. exit4:
  172. print b$
  173. end 4
  174. exit5:
  175. print b$
  176. end 5
  177. exit6:
  178. print b$
  179. end 6
  180. exit7:
  181. print b$
  182. end 7
  183. exit8:
  184. print b$
  185. end 8
  186. exit9:
  187. print b$
  188. end 9
  189. exit10:
  190. print b$
  191. end 10
  192. exit11:
  193. print b$
  194. end 11
  195. exit12:
  196. print b$
  197. end 12
  198. exit13:
  199. print b$
  200. end 13
  201. exit14:
  202. print b$
  203. end 14
  204. exit15:
  205. print b$
  206. end 15
  207. exit16:
  208. print b$
  209. end 16
  210. exit17:
  211. print b$
  212. end 17
  213. exit18:
  214. print b$
  215. end 18
  216. exit19:
  217. print b$
  218. end 19
  219. exit20:
  220. print b$
  221. end 20
  222. exit21:
  223. print b$
  224. end 21
  225. exit22:
  226. print b$
  227. end 22
  228. exit23:
  229. print b$
  230. end 23
  231. exit24:
  232. print b$
  233. end 24
  234. exit25:
  235. print b$
  236. end 25
  237. exit26:
  238. print b$
  239. end 26
  240. exit27:
  241. print b$
  242. end 27
  243. exit28:
  244. print b$
  245. end 28
  246. exit29:
  247. print b$
  248. end 29
  249. exit30:
  250. print b$
  251. end 30
  252. exit31:
  253. print b$
  254. end 31
  255. exit32:
  256. print b$
  257. end 32
  258. exit33:
  259. print b$
  260. end 33
  261. exit34:
  262. print b$
  263. end 34
  264. exit35:
  265. print b$
  266. end 35
  267. exit36:
  268. print b$
  269. end 36
  270. exit37:
  271. end 37
  272. exit38:
  273. end 38
  274. exit39:
  275. end 39
  276. exit40:
  277. end 40
  278. exit41:
  279. end 41
  280. exit42:
  281. end 42
  282. exit43:
  283. end 43
  284. exit44:
  285. end 44
  286. exit45:
  287. end 45
  288. exit46:
  289. end 46
  290.  
  291. rem Here is the routine to just pause while printing the message of your choice.
  292.  
  293. message:
  294. e$=mid$(a$,5,79)
  295. print e$;
  296.  
  297. wait2:
  298. a$=inkey$
  299. if a$="" then wait2:
  300. goto finish:
  301.  
  302. rem Get only y(Y) or n(N) response if /q (question) parameter selected.
  303.  
  304. getyn:
  305. ac$=mid$(a$,5,79)
  306. ad$=ac$+"(y/n) "
  307. print ad$;
  308.  
  309. wait3:
  310. a$=inkey$
  311. if a$="" then wait3:
  312. if a$="y" then exit2b:
  313. if a$="Y" then exit2b:
  314. if a$="n" then exit1b:
  315. if a$="N" then exit1b:
  316. b$=chr$(27)
  317. if a$=b$ then exit0:
  318. goto wait3:
  319.  
  320. exit2b:
  321. print a$
  322. end 2
  323. exit1b:
  324. print a$
  325. end 1
  326.  
  327. help:
  328. print wait$
  329. cls
  330. print "To print a message and get a response from a-z, A-Z, 0-9, the function"
  331. print "keys, or the Esc key, the syntax is GETKEY /e Message.  Message can be"
  332. print "up to 79 characters (including spaces) long.  An errorlevel is returned"
  333. print "depending on the key pressed.  A-Z return a code of 0-26.  Either"
  334. print "upper or lower case can be used.  0-9 return a code of 27-36.  The"
  335. print "function keys return 37-46.  Esc returns an errorlevel of 0."
  336. print
  337. print
  338. print "To just print a message, pause, and wait for any key to be pressed,"
  339. print "the syntax is GETKEY /m Message.  Message can be up to 79 characters"
  340. print "long, including spaces."
  341. print
  342. print
  343. print "To get a y or n response, or the Esc key, translated into errorlevel"
  344. print "2, 1, or 0, the syntax is GETKEY /q Yes or no question."
  345. print
  346. print
  347. print "To get this help screen, the syntax is GETKEY /?."
  348. print
  349. print
  350. print "If this screen hasn't helped, and you still can't get the program going,"
  351. print "please consult GETKEY.DOC, or call me between 9AM and 9PM EST.  Ask for" 
  352. print "Matt.   (802)223-2553"
  353.  
  354. finish:
  355. end
  356.